[Dancer-users] config.yml options not visible to Dancer::Template::HtmlTemplate

David Precious davidp at preshweb.co.uk
Tue Mar 20 16:29:08 CET 2012


Sorry for the slow reply.

On Sun, 18 Mar 2012 18:23:59 +0000
GJ <gj at freeshell.org> wrote:
 
> While I can set my needed options for HTML::Template in config.yml
> per the documentation/guidance of the list, it never reaches
> Dancer::Template::HtmlTemplate.  The issue is here, in
> HtmlTemplate.pm, in in the render method :
> 
> ----
>     my $ht = HTML::Template->new(
>         filename => $template,
>         die_on_bad_params => 0, # Required, as we pass through other
> params too
>         %{$self->config}
>     );
>     $ht->param($tokens);
>     return $ht->output;
> ----
> 
> The problem is that $self->config is empty here.  I'm using version
> 0.06.

What does your config.yml look like?


> Also, I don't necessarily want die_on_bad_params hard coded that way.

Without it, unless you use all of the stuff Dancer provides
automatically to the template (details of the request, config, etc),
HTML::Template will die; that's probably not helpful.

 
> Besides that, what I really miss is the ability to do this sort of
> thing:
> 
> ----
> if (condition) {
>     set a certain param for the template
> } else {
>     set some other param
> }
> ----
> 
> I can't do this because the module doesn't inherit the param method
> from HTML::Template.  Can't Dancer be wangled into setting template
> tokens in multiple places for a given route, or must it happen all at
> once?

The typical Dancer way of handling it is a single "render this template
with these params" action.

You could, of course, build up the params you want to pass to your
template individually, then hand them off at the end - e.g.:

  get '/foo' => sub {
      my %template_params;
      if (params->{foo}) {
          $template_params->{foo} = 'Some foo';
      }
      # ... etc ....

      template 'foo', \%template_params;
  } 


> Side note -- whitespace is apparently syntactically significant in
> YAML.  Of what possible benefit is that? 

Yeah, that's just how YAML is.   Some like it (Python fans), some don't.

You never know, it's possible that Dancer2 might support various config
file formats, so you could write your config in JSON if it felt more
natural to you.

Cheers

Dave P

-- 
David Precious ("bigpresh") <davidp at preshweb.co.uk>
http://www.preshweb.co.uk/     www.preshweb.co.uk/twitter
www.preshweb.co.uk/linkedin    www.preshweb.co.uk/facebook
www.preshweb.co.uk/cpan        www.preshweb.co.uk/github


More information about the Dancer-users mailing list