[Dancer-users] Template vars in the layout

Robert Olson bob at rdolson.org
Sat Mar 27 23:29:25 UTC 2010

Sure - how about something like this in the layout section on the main  
Dancer page:

A layout is a special view, located in the 'layouts' directory (inside  
the views directory) which must have a token named `content'. That  
token marks the place where to render the action view. This lets you  
define a global layout for your actions. Any tokens that you defined  
when you called the 'template' keyword are available in the layouts,  
as well as the standard session, request, and params tokens. This  
allows you to insert per-page content into the HTML boilerplate, such  
as page titles, current-page tags for navigation, etc.

Perhaps the example should then look like

		<title>[% page_title %]</title>
         <div id="header">

         <div id="content">
         <% content %>

This layout can be used like the following:

     use Dancer;
     use Template;

     layout 'main';

     get '/' => sub {
         template 'index' => {
				page_title => "Your website homepage",

BTW I'm thoroughly enjoying a build of an app using Dancer. I'm  
getting it done hugely faster than the classic cgi-per-page way I've  
been doing for too many years.


On Mar 27, 2010, at 6:16 PM, sawyer x wrote:

> no problem. The fact you weren't sure might mean the docs missed  
> expressing it. Would you be interesting in helping form some change  
> to the docs so others won't get confused?
>> On Mar 27, 2010 11:32 PM, "Robert Olson" <bob at rdolson.org> wrote:
>> Doh, I cleverly read the code but missed the first half of
>> 	{%$tokens, content => $content})
>> Thanks much.
>> --bob
>> On Mar 27, 2010, at 3:26 PM, sawyer x wrote: > I'm actually at the  
>> movies now but I wanted to tak...

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.backup-manager.org/pipermail/dancer-users/attachments/20100327/d773f800/attachment.htm>

More information about the Dancer-users mailing list