[Nitro] Nitro templating question
james_b at neurogami.com
Sat Jan 7 14:44:22 EST 2006
Bryan Soto wrote:
> So rather than elements, James would like external layouts similar to
> Rails and Rob would like to be able to specify external template files
> rather than coding the view in the element itself. Correct?
Not quite. I'm not asking that Elements go away or anything, or that I
can't find a use for them, but I am looking for a simple way to do
Dreamweaver-style templates when I want to.
Dreamweaver lets you create a template that defines an entire page (what
Rials calls a 'layout'), with slots for inserting free-form content or
calls to library templates (which render small chunks of stuff; what
Rials calls 'partials').
Dreamweaver was the first place I saw this template style; I used Rails
as an example because I thought most here would be reasonably familiar
with it, but it's not unique or original to Rails, and I don't want to
encourage Rails/Nitro comparisons, because I think they serve different
Bryan's earlier reply to my inquires got me pointed in the right
direction, and I had little trouble making use of Elements and Pages.
And indeed it would be trivial to write my code to slurp in a disk file
rather than have the HTML stuffed into a method. Whether or not there
should be a built-in Nitro way to do that file-slurping is another
matter. I'd like to see it, because I think that's something I would
use, but since Ruby/Nitro makes it easy to alter things, it isn't essential.
> So how should it work?
> According to the Rails book, a layout should be defined with the same
> name as the controller, and any action called on that controller will
> use that template. I'm sure they also have a method where you can
> specify a different name. So that's one option.
I've been a big fan of convention over configuration since the late
'90s, and I like the idea that if I simple name something correctly and
place it in a reasonable spot, Nitro will just Do The Right Thing.
For example, if I have a file named main.layout.xhtml in my templates
directory, Nitro could just figure out that I want to use a layout for
the main controller. Methods that that do not want a layout would then
need to say so, or they could explicitly request the use of a different
If there is no *.layout.* file, then it is assumed that none is to be
used unless a controller method explicitly asks for one by name.
http://www.ruby-doc.org - Ruby Help & Documentation
http://www.artima.com/rubycs/ - Ruby Code & Style: Writers wanted
http://www.rubystuff.com - The Ruby Store for Ruby Stuff
http://www.jamesbritt.com - Playing with Better Toys
http://www.30secondrule.com - Building Better Tools
More information about the Nitro-general