Re: [Templates] Filter inside a vmethod

[prev] [thread] [next] [Date index for 2005/02/10]

From: Bill Moseley
Subject: Re: [Templates] Filter inside a vmethod
Date: 21:29 on 10 Feb 2005
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(' &#187; ');
%]

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

[Templates] Filter inside a vmethod
Bill Moseley 00:24 on 10 Feb 2005

Re: [Templates] Filter inside a vmethod
Andy Wardley 09:44 on 10 Feb 2005

Re: [Templates] Filter inside a vmethod
Vivek Khera 16:25 on 10 Feb 2005

Re: [Templates] Filter inside a vmethod
Bill Moseley 21:29 on 10 Feb 2005

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