[Templates] passing positional arguments to MACROs
Bill Moseley
moseley at hank.org
Mon Mar 17 17:56:01 GMT 2008
On Mon, Mar 17, 2008 at 02:14:19PM +0100, Thomas Klausner wrote:
> I'm currently trying to pass some arbitrary values (basically a list)
> through a macro:
>
> [% MACRO mt(msg) GET c.maketext(msg) %]
>
> [% mt("Hello %1", c.user.name %]
> [% mt("%1 does %2", 'foo', 'bar' %]
>
> 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'] %]
Yes that's what I do, basically.
I have a macro loc() that I use like this when it's simple text:
loc( 'Hello world' );
And then when I need to pass parameters I do this:
loc( ['Hello [_1]', 'world' ] );
--
Bill Moseley
moseley at hank.org
More information about the templates
mailing list