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@wundersolutions.com http://www.wundersolutions.com http://twitter.com/wundercounter 866 503 2204 (Toll free - North America) 416 944 8306 (direct)
On Fri, May 14, 2010 at 4:44 PM, Olaf Alders <olaf@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@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@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
On 2010-05-14, at 7:51 PM, Naveed Massjouni wrote:
'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 %]
Hi Naveed, Thanks very much for this, but it doesn't quite solve my problem. I've got the following in my layout/main.tt <html> <head> <title>[% title %]</title> ... Now, since I'm using auto_page, the web designer can add pages as he sees fit and the routes will be created. What I'd like him to be able to do is to set the title tags from within individual pages. Eg in contact.tt: [% title = 'Contact Us' %] I had thought that the layouts would be using TT's wrapper functionality, which would enable this, but that's not the case. So, my workaround is something like this in main.tt: [% title = 'default title' %] [% IF request.path == '/' %] [% title = 'home page title' %] [% ELSIF request.path == '/contact' %] [% title = 'contact page title' %] [% END %] 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? Thanks, Olaf -- Olaf Alders olaf@wundersolutions.com http://www.wundersolutions.com http://twitter.com/wundercounter 866 503 2204 (Toll free - North America) 416 944 8306 (direct)
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@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)
participants (3)
-
David Precious -
Naveed Massjouni -
Olaf Alders