[dancer-users] Dancer2 template engines and config

David Golden xdg at xdg.me
Tue Mar 5 19:28:17 GMT 2013


On Tue, Mar 5, 2013 at 1:08 PM, WK <wanradt at 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/Dancer2/Session/Cookie.pm

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 at xdg.me>
Take back your inbox! → http://www.bunchmail.com/
Twitter/IRC: @xdg


More information about the dancer-users mailing list