In the following (working in Ruby 1.8.6) code snippet, forget for the moment that the templates and CSS are inline and no helpers are used....and imagine that the templates are in separate files.
Is this style of using partials in both the main layout and in sub-templates how templates are best modularized using Sinatra + HAML?
TIA, Jon
# wowee.rb
require 'sinatra'
get '/' do
haml :index
end
__END__
@@ layout
%html
%head
%body
#header= haml :header, :layout => false
= yield
#footer= haml :footer, :layout => false
@@ index
%h1 Hello World
@@ header
%span Default Header
@@ footer
Copyright ©
= Time.now.year
= haml :company, :layout => false
@@ company
%span{ :style => 'font-weight: bold; font-style: italic;' } Dynamically Created Co.
Defaulting :layout to false when rendering templates that begin with
"_" is an interesting idea. We're also considering defaulting :layout
to false when rendering a template within another template:
http://sinatra.lighthouseapp.com/projects/9779/tickets/181
I'm not very happy with the patch but it seems like a good concept.
Thanks,
Ryan
+1
While I like the assumptions based upon the leading "_" convention (or Ryan's "where am I rendering from" based idea), should this new behavior be overridable via a set option?
I'm too noob to Sinatra to have a use case yet as to why an option would be useful, but as I'm trying to wrap my head around how to write sub-templates that can select their layout (think overall site layout with ability to have multiple "content section" sub-layouts selectable by the sub-templates similar to ASP.NET's nested Master Pages), my spidey sense thinks we may need the ability to make the :layout => false assumption(s) overridable.
I suspsect there may already be a perfectly great way to do this, and I just haven't stumbled upon it yet. Links appreciated if it does.