> Is it possible to set a default value in a Template::Service PROCESS?
> 
> I've tried doing:
> 
>  [% DEFAULT template.foo = 'bar' %]
> 
> but it just gets ignored.

It looks like TT2's Stash::set() will not set values in any blessed
object (other than Template::Stash of course).  Assigning

    template.foo = 'bar'

actually incorrectly falls through to attempting to call foo as a
$template method.

One fix is to replace $rootref eq 'HASH' with UNIVERSAL::isa($root, 'HASH')
(and similarly for $rootref eq 'ARRAY') in Stash::_assign().  But this
might need a bit more thought: should non-stash blessed objects be
modifiable?

In the meantime, yes, you have to do something like:

> Do I really have to do:
> 
>   [% IF template.foo;
>        SET myfoo = template.foo;
>      ELSE;
>        SET myfoo = 'bar';
>      END;
>   %]
> 
> and then use myfoo instead of template.foo?

or you could write this more concisely as either of:

    [% myfoo = template.foo ? template.foo : 'bar'; %]
    [% myfoo = template.foo || 'bar'; %]

BTW, the META directive allows you to modify the template object.
Perhaps this does what you need?

    [% META foo = 'bar' %]

(although there is no way I know of handling DEFAULT since you can't
have an expression on the RHS of a META.)

Craig


Reply via email to