Re: [Templates] Filter inside a vmethod
[prev]
[thread]
[next]
[Date index for 2005/02/10]
On Thu, Feb 10, 2005 at 11:25:11AM -0500, Vivek Khera wrote:
>
> On Feb 9, 2005, at 7:24 PM, Bill Moseley wrote:
>
> >Is the parser not able to do this?
> >
> > foo.push( item.name | html );
>
> Not only that, but it can't even deal with simple concatenation or any
> other operators in there. I find my self always pre-computing whatever
> I need to pass to a vmethod and sticking it in a variable to pass in.
I often wish for a map vmethod, too. What I might do in perl (for,
say a breadcrumb ):
join '»', map {
$_->here ? $_->text : qq[<a href="$_->url">$_->text</a>]
} @links;
(escaping where needed) and in the Template I do:
[%-
mylist = [];
FOR item = page.trail;
SET escaped = item.name | html;
SET tooltip = " title=\"$item.tooltip\"" IF item.tooltip;
IF item.here;
mylist.push( escaped );
ELSE;
mylist.push( "<a href=\"$item.url\" $tooltip>$escaped</a>" );
END;
END;
mylist.join(' » ');
%]
I suppose the second is easier to read.
--
Bill Moseley
moseley@xxxx.xxx
_______________________________________________
templates mailing list
templates@xxxxxxxxxxxxxxxx.xxx
http://lists.template-toolkit.org/mailman/listinfo/templates