Here's another possibility if for some reason you don't like suggestions
from Sean or Josh:
[%
SET a = [];
SET b = [];
FOREACH user IN list;
IF user.isLoggedIn;
a.push(user);
ELSE;
b.push(user);
END;
END;
�%]
And now you can call your block:
[% PROCESS table rows=a %] - show first table
[% PROCESS table rows=b %] - show second table
For something more generic, you could define a simple filtering VMethod
for arrays:
$Template::Stash::LIST_OPS->{filter} = sub {
my ($list, $filter, $negate) = @_;
return [ grep { $_->$filter xor $negate } @$list ];
};
and in the template:
[% PROCESS table rows = users.filter('isLoggedIn') %]
[% PROCESS table rows = users.filter('isLoggedIn', 1) %]
HTH.
-M.
> ---------- Original Message ----------
> From: Michael Wichmann <[EMAIL PROTECTED]>
> To: Mihai Bazon <[EMAIL PROTECTED]>
> Date: Thursday, October 30, 2008 / 4:43pm GMT
> Subject: Re: [Templates] Applying Filters in an IF condition
>
> | Mihai Bazon wrote:
> |
> | I for one don't quite understand why/how you want to use this, but
> | probably a simple way is to use a variable:[% SET condition =
> | something | eval; IF condition %] ... [% END %]
> | Could you better explain your intentions...?
> | -M.
> Hi Mihai,
>
> let me explain my intention:
>
> There is some data from a database which has to be shown in a table.
> But I want to split the information into two tables without querying the
> database again.
> So I do need table filters to prevent writing the same code twice.
>
> My idea is:
>
> - the Table structure with headers and rows becomes a block.
> - the part that renders the rows depends on a filter expression
> - I can call the block with PROCESS and a filtering criteria which has to
> be evaluated
>
> -> like this [% PROCESS table filter="user.isLoggedIn"%]
> -> or that [% PROCESS table filter="NOT user.isLoggedIn" %]
>
> With this, only the rows with logged in users are shown and vice versa.
>
> But how do I assemble a directive like this [% IF user.isLoggedIn %] with
> the filter parameter from the PROCESS call?
> Which, by the way gets evaluated correctly?
>
> I hope this is detailed enough :-)
>
> Michael
>
>
>
>
>
>
> ________________________________________________________________________
> Schon geh�rt? Bei WEB.DE gibt' s viele kostenlose Spiele:
> http://games.entertainment.web.de/de/entertainment/games/free/index.html
>
>
> _______________________________________________
> templates mailing list
> [email protected]
> http://mail.template-toolkit.org/mailman/listinfo/templates_______________________________________________
templates mailing list
[email protected]
http://mail.template-toolkit.org/mailman/listinfo/templates