[Nitro] Question about include files
James Britt
james_b at neurogami.com
Sat Jun 3 21:14:22 EDT 2006
I'm trying to write abut how Nitro lets you reuse page chunks. One way
is to use include files:
<render href='some_partial_thing' />
And then there'd be a file, some_partial_thing.xhtml or
some_partial_thing.xinc in the template path.
I had some problems getting this working right (I think there are
ordering issues when setting Template.root and also calling mount_at for
controllers), and noticed the messages coming from the WEBbrick server.
I *think* that you can use the <render> syntax to invoke a method|action
on the parent controller.
I tried an experiment. I had my index.xhtml template include
<render href='copyright' />
And then added a 'copyright' method to the main controller, but did not
provide a corresponding view file.
So the code is this:
def copyright
STDERR.puts "MainController#copyright"
"Hey! (c)"
end
and when i call the page I can see the STDERR message, but the string
returned from the method never appears in the view.
What am I misunderstanding about the use of controller methods in place
of include files?
If I change that method to use
@out << "Hey! (c)"
then it works, but that seems a bit hackish.
I guess I'm hoping that <render> is just another way to invoke actions,
but perhaps their place in the rendering sequence prevent this.
I also now see that this:
def copyright
STDERR.puts "MainController#copyright"
@c = "Hey! (c)"
end
will work fine when I have copyright.xhtml in the template path.
But I can't seem to get the raw return value of the method to render.
(BTW, after my code change to how "mount_at" works, I see that I can
have multiple template paths for a controller by calling mount_at
multiple times. I believe this is the intended behavior, based on the
comments in include.rb and it referring to Nitro searching the
"template_root stack" if the included file is referenced with a relative
path. Is this correct?)
--
James Britt
"The greatest obstacle to discovery is not ignorance, but the illusion
of knowledge."
- D. Boorstin
More information about the Nitro-general
mailing list