In-code template configuration - order matters?
Hi, given this simple template: <h2><% name %></h2> And this code: #!/usr/bin/env perl use Dancer2; set engines => { template => { template_toolkit => { start_tag => '<%', end_tag => '%>', } } }; set template => "template_toolkit"; get '/' => sub { template 'demo', { name => 'Perl Maven' }; }; dance; I see the expected display, but if I change the order of the two 'set' statements then I just get <h2><% name %></h2> as output. Why is that? Gabor ps. I don't have any configuration files. This is a stand-alone script with an external tt file.
On 2015-08-25 06:14 PM, Gabor Szabo wrote:
Why is that?
I would expect it's because the "set template => 'template_toolkit'" initialize the template engine, and since you haven't defined your custom arguments yet, it'll take in the defaults. And when you do pass your custom arguments on the next line, it's too late and won't be used. This being said, I haven't checked the code, so that's just a hunch. :-) Joy, `/anick
This is it exactly. @yanick This is what I tried to patch in D1 (and failed). From the looks of it D2 has the same kind of issue. On Wed, Aug 26, 2015 at 2:20 AM, Yanick Champoux <yanick@babyl.dyndns.org> wrote:
On 2015-08-25 06:14 PM, Gabor Szabo wrote:
Why is that?
I would expect it's because the "set template => 'template_toolkit'" initialize the template engine, and since you haven't defined your custom arguments yet, it'll take in the defaults. And when you do pass your custom arguments on the next line, it's too late and won't be used.
This being said, I haven't checked the code, so that's just a hunch. :-)
Joy, `/anick _______________________________________________ dancer-users mailing list dancer-users@dancer.pm http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
On 26/08/2015 01:20, Yanick Champoux wrote:
I would expect it's because the "set template => 'template_toolkit'" initialize the template engine, and since you haven't defined your custom arguments yet, it'll take in the defaults. And when you do pass your custom arguments on the next line, it's too late and won't be used.
Yet it doesn't seem to matter when the order is changed in config.yml (at least that's the case with [% %] tags). Why does that behave differently? -- Richard Jones
On 2015-08-27 04:18 AM, Richard Jones wrote:
Yet it doesn't seem to matter when the order is changed in config.yml (at least that's the case with [% %] tags). Why does that behave differently?
Because the YAML document is read as a whole, and then the code that deals with it parses its bits and pieces internally according to the right order of precedence. Whereas the two statements in perl-space force the (alas, wrong) order of precedence. Joy, `/anick
participants (4)
-
Fabrice Gabolde -
Gabor Szabo -
Richard Jones -
Yanick Champoux