[Templates] passing positional arguments to MACROs
Josh Rosenbaum
josh at infogears.com
Tue Mar 18 17:37:01 GMT 2008
Thomas Klausner wrote:
> Hi!
>
> On Mon, Mar 17, 2008 at 02:14:19PM +0100, Thomas Klausner wrote:
>
>> The problem ist that the above macro definition does not work like this.
>> Using named parameters seems cumbersom. One alternative would be to pass
>> the params in as an arrayref:
>>
>> [% mt("%1 does %2", ['foo', 'bar'] %]
>
> Thanks for the feedback, we're going for the arrayref solution...
One other solution might be to pass an mt subroutine via the vars parameter. Then you could do exactly what you are wanting. I'd imagine you might only want to do this if you have access to the c object (used to call maketext) outside of TT and if you will be using mt() in the processed templates.
So your vars would be something like:
{
mt => sub{ return $c->maketext(@_); }
}
-- Josh
More information about the templates
mailing list