Michael Wichmann wrote:
> 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 :-)

There are a bunch of other alternatives here, I'll give a couple. (Not sure if 
they'd be better or not. I'll leave that up to you to decide or figure out.)

This first one kind of depends on how crazy your filter needs to be. If it is 
this simple use case or even a couple more filters, I'd just do something like:
[% PROCESS table use_logged_in = 1 %]
[% PROCESS table use_logged_in = 0 %]
Then your foreach would have something like this at the top:
[% NEXT IF use_logged_in != user.isLoggedIn %]


Another way if the tables aren't very big and you have plenty of memory, you 
could do a single loop with something like this:
[% FOREACH row IN list %]
  [% IF user.isLoggedIn %]
    output stuff here.
  [% ELSE %]
    [% second_data = BLOCK %]
      second table output stuff here
    [% END %]
    [% second_table = second_table _ second_data %]
  [% END %]
[% END %]
[% second_table %]

Disclaimer: None of these are tested and may need some tweaking.

-- Josh

_______________________________________________
templates mailing list
[email protected]
http://mail.template-toolkit.org/mailman/listinfo/templates

Reply via email to