Dancer2 template engines and config
Tere! I tried to ask same question at IRC too, but got no answers. I try add some bits more here. I like D:T:Xslate template engine and am trying to convert it to Dancer2. I have trouble understanding some points how template engines should get data from config file. When i look 3 default templates, they all rely on $self->config but $self->config carries only two attributes in: environment and location. And those 2 are not from config-file. When i tried to change defaults of template_toolkit plugin in config file, they did not worked. I tried to change start_tag and end_tag, but defaults overrun them and from code i see, that alternative tags are looked from $self->config->{'start_tag'}. Which are not available through $self->config. Some days ago i got suggestion from racke to look toward $self->context->app->config. Yes, this is possible, but i have not seen it in default engines. And to get config into, one should write something like $self->context->app->config->{engines}{template_toolkit}. It seems a bit complicated. Should this be the official/idiomatic way to get config for template? -- Wbr, Kõike hääd, Gunnar
On Tue, Mar 5, 2013 at 1:08 PM, WK <wanradt@gmail.com> wrote:
I like D:T:Xslate template engine and am trying to convert it to Dancer2. I have trouble understanding some points how template engines should get data from config file.
+1 I'm very glad you're porting that, though RSIMOES might have just beaten you to it: https://metacpan.org/module/Dancer2::Template::Xslate -- but as you'll see I'm not sure it's right. For the record, I believe the way to do this is to add the config keys you're interested in as attributes of the class you're building. Then the config keys/values go under the engine section in the config for that type and class. See how Dancer2::Session::Cookie does it. https://metacpan.org/source/DAGOLDEN/Dancer2-Session-Cookie-0.002/lib/Dancer... Any data under engines/template/class would passed to the class constructor. E.g. if your class has 'foo' and has 'wibble', then you'd config like this: template: MyTemplateClass engines: template: MyTemplateClass: foo: bar wibble: wobble That's *not* what is documented in Dancer2::Template::Xslate, so I don't know if he's come up with a shortcut or if it's just wrong. David -- David Golden <xdg@xdg.me> Take back your inbox! → http://www.bunchmail.com/ Twitter/IRC: @xdg
2013/3/5 David Golden <xdg@xdg.me>:
I'm very glad you're porting that, though RSIMOES might have just beaten you to it: https://metacpan.org/module/Dancer2::Template::Xslate -- but as you'll see I'm not sure it's right.
This is good news, i wrote to him directly too. I got same (bad) response with his module also, so i am already suspecting my fault in some other place now. -- Wbr, Kõike hääd, Gunnar
participants (2)
-
David Golden -
WK