[Dancer-users] Accessing template vars in layout

David Precious davidp at preshweb.co.uk
Sun May 16 15:22:58 CEST 2010


On Sunday 16 May 2010 13:14:04 Olaf Alders wrote:
> That gets the job done, but it's not nearly as clean as I'd like and I need
>  to trust the web designer to get the syntax correct etc.  Is there a way
>  to get Dancer::Template::TemplateToolkit to use a wrapper by default?

Hmm.  Currently Dancer proceses the view and the layout separately; from a 
brief glimpse at docs on TT's wrapper directive, it looks like it may work for 
us:

http://template-toolkit.org/docs/manual/Directives.html#section_WRAPPER

When I have a moment, I'll have a crack at making it work.

Since ideally we wouldn't want to change behaviour by forcing the user to add 
a [% WRAPPER %] around their views, I think we'd need to read the view 
ourselves, add the [% WRAPPER %] stuff to make use of the selected layout (if 
there is one), then pass the modified view to TT to render; seeing the 
wrapper, it should automatically wrap the layout template around the view 
appropriately, I think.

Thanks for bringing this up; it would indeed be nice for things declared in 
the view to be accessible in the layout!

Cheers 

Dave P


-- 
David Precious <davidp at preshweb.co.uk>
http://blog.preshweb.co.uk/    www.preshweb.co.uk/twitter
www.preshweb.co.uk/linkedin    www.preshweb.co.uk/facebook
www.preshweb.co.uk/identica    www.lyricsbadger.co.uk

  "Programming is like sex. One mistake and you have to support 
  it for the rest of your life". (Michael Sinz)


More information about the Dancer-users mailing list