[Dancer-users] Accessing template vars in layout

Naveed Massjouni naveedm9 at gmail.com
Sat May 15 01:51:21 CEST 2010


On Fri, May 14, 2010 at 4:44 PM, Olaf Alders <olaf at wundersolutions.com> wrote:
> Hi All,
>
> I'm totally new to Dancer, but I did manage to set up a Dancer app in no time at all last week, which is great.   My config.yml looks like this:
>
> layout: "main"
> logger: "file"
> auto_page: 1
> template: template_toolkit
> engines:
>    template_toolkit:
>        start_tag: '[%'
>        stop_tag: '%]'
>        INTERPOLATE: 1
>
> With this setup, I wasn't able to make TT variables which I set in the various templates available in the layout.  Am I missing something?  I did a fair amount of digging, but I couldn't figure it out.  Any tips are appreciated.
>
> Thanks,
>
> Olaf
> --
> Olaf Alders
> olaf at wundersolutions.com
>
> http://www.wundersolutions.com
> http://twitter.com/wundercounter
>
> 866 503 2204 (Toll free - North America)
> 416 944 8306 (direct)
>
> _______________________________________________
> Dancer-users mailing list
> Dancer-users at perldancer.org
> http://www.backup-manager.org/cgi-bin/listinfo/dancer-users

I'm not sure about accessing variables inside your layout that you
have created inside of a template in your views folder.  But you can
access variables that you pass from your route:

If you had the following route:
  get '/foo' => sub {  template foo => { user => 'bob' } };

Then in your layout, you would be able to access the variable user
just like you can inside of a template.  So in views/layout/main.tt
you can have:
  hello [% user %]

-Naveed


More information about the Dancer-users mailing list