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

GJ gj at freeshell.org
Thu Mar 22 22:15:04 CET 2012


Hi David,

I did some more investigation into this.

On Tue, Mar 20, 2012 at 03:29:08PM +0000, David Precious wrote:
> 
> 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.

It looks like the HTML::Template directives I've placed in config.yml that are
supposed to be in %{$self->config} are buried in the guts of %$tokens.  It
should be possible to dig them out and then pass them off to HTML::Template in
render() right? That is presuming that it is not supposed to be inheriting that
method from elsewhere.  

> > 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.
> 

It seems that you are talking about the same variables that are transformed in
_flatten, yes? IMHO, the best thing would be save them off since the module is
digging them out of %$tokens anyways and plop them in front of the user's own
TMPL_VARs at the point that they are being passed on to HTML::Template's param
method.

That way, you leave die_on_bad_params alone, thereby preserving whatever
behaviour is expected by the user, who is after all likely to be used to
having the ability to set or not set that directive.

Besides, if my config.yml was being parsed by this module correctly, then if I
had set die_on_bad_params to true in config.yml, as I am wont to do, it could
have thereby overridden the hard-coded setting and thus have caused a mess
anyways.

>  
> > 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.

Noted. I am trying to avoid code rewriting wherever possible but this seems
like a reasonable compromise.

Thanks
GJ


More information about the Dancer-users mailing list