Re: [Templates] setting macro parameters at run time

[prev] [thread] [next] [Date index for 2004/06/18]

From: Jens Porup
Subject: Re: [Templates] setting macro parameters at run time
Date: 06:06 on 18 Jun 2004
On Fri, Jun 18, 2004 at 01:52:50AM -0400, Mark Mills wrote:
> Jens Porup wrote:
> >Is there a way to set the parameters to a macro at run time?
> >
> >So I have a macro like so:
> >
> >	[%- MACRO foo(bar,baz) BLOCK -%]
> >	[%# do some stuff here %]
> >	[%- END -%]
> >
> >But I want to call the macro like so:
> >
> >	<td>foo(bar="blah", baz= "blah" _ [% ANOTHER_VARIABLE %])</td>
> 
> I think you'd want to do this:
> 
> [% tempbaz = "blah" _ ANOTHER_VARIABLE %]
> <td>[% foo(bar="blah", baz=tempbaz) %]</td>
> 
> The parser doesn't much like inline string construction in calls, you 
> normally need to build the argument first in a single variable and then 
> pass that.

I've tried that:

	[% set foo = "Collection Occasions<a href=\"" _ PUBLISH_DESTINATION _
	"/tech_spec/collection_occasions.html\"><sup>?</sup></a>" %]

	<tr><th colspan=2>[% filter("rt=COD",foo) %]</th></tr>
	
and so I still get:

file error - parse error - report.tt2 line 47: unexpected token (foo)
  [% set foo = "Collection Occasions<a href=\"" _ PUBLISH_DESTINATION _
  "/tech_spec/collection_occasions.html\"><sup>?</sup></a>" %]

Do you see the problem?

I want to prepend a global url to my parameter. 

This means I need to insert a template variable in the middle of the paramter
being passed to my macro.

So the question really is, how does template toolkit preprocess variables?
Before or after entering macro land? And how do I work around whatever those
limitations are?

Thanks,

Jens


_______________________________________________
templates mailing list
templates@xxxxxxxxxxxxxxxx.xxx
http://lists.template-toolkit.org/mailman/listinfo/templates

Re: [Templates] setting macro parameters at run time
Jens Porup 06:06 on 18 Jun 2004

Generated at 08:55 on 15 Mar 2005 by mariachi v0.52