[ic] interpolate
Elver Loho
elver.loho at gmail.com
Sat Mar 25 05:56:45 EST 2006
On 3/25/06, Kevin Walsh <kevin at cursor.biz> wrote:
> "Elver Loho" <elver.loho at gmail.com> wrote:
> > On 3/24/06, Kevin Walsh <kevin at cursor.biz> wrote:
> > > "Elver Loho" <elver.loho at gmail.com> wrote:
> > > Well, firstly, it looks as if you're mixing positional and named
> > > parameters. You can either do [lc2 first second] or
> > > [lc2 foo=first bar=second], but not mix the two. That'll be
> > > the reason why you always get the default message when you do that.
> >
> > How do I unpack named variables? Right now am using my ($code, $message) = @_;
> >
> If you have a UserTag like this:
>
> UserTag foobar Order foo bar baz
>
> then you have three named arguments, which you can use like this:
>
> [foobar foo="aaa" bar="bbb" baz="ccc"]
>
> You can put the args in any order you like. The tag code will receive
> them in the order you specified in the UserTag "Order" config.
>
> In your UserTag code, you can collect the args like this:
>
> my ($foo,$bar,$baz) = @_;
>
> The variable names are irrelevant, but it's useful to name them after
> the Order values.
>
> If you make your UserTag into a container, like this:
>
> UserTag foobar HasEndTag 1
> UserTag foobar Order foo bar baz
>
> then you can use your tag like this:
>
> [foobar foo="aaa" bar="bbb" baz="ccc"] Tag body [/foobar]
>
> Now you have an extra argument, which you collect like this:
>
> my ($foo,$bar,$baz,$body) = @_;
>
> If you want your tag body to be interpolated by default (no need
> to specify interpolate=1) then you define it like this:
>
> UserTag foobar HasEndTag 1
> UserTag foobar Interpolate 1
> UserTag foobar Order foo bar baz
>
> You can also create "on the fly" tag arguments, like this:
>
> UserTag foobar HasEndTag 1
> UserTag foobar Interpolate 1
> UserTag foobar AddAttr 1
> UserTag foobar Order foo bar baz
>
> Your collection for the above should look like this:
>
> my ($foo,$bar,$baz,$body,$opt) = @_;
>
> With AddAttr, you can pass an argument that's not in your "Order"
> list and see it in your tag code, for instance:
>
> [foobar foo="aaa" kevin="bbb"] Tag body [/foobar]
>
> In the above case, $foo will be "aaa", $bar and $baz will be undef.
> $body will be " Tag body " and $opt->{kevin} will be "bbb". Note that
> $opt is a hashref.
>
> There are lots of other things you can do, but this article is probably
> long enough for the moment. :-)
>
> --
> _/ _/ _/_/_/_/ _/ _/ _/_/_/ _/ _/
> _/_/_/ _/_/ _/ _/ _/ _/_/ _/ K e v i n W a l s h
> _/ _/ _/ _/ _/ _/ _/ _/_/ kevin at cursor.biz
> _/ _/ _/_/_/_/ _/ _/_/_/ _/ _/
> _______________________________________________
> interchange-users mailing list
> interchange-users at icdevgroup.org
> http://www.icdevgroup.org/mailman/listinfo/interchange-users
>
Thank you! That was a great and useful reply :)
Elver
More information about the interchange-users
mailing list