Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mako templates inline if statement

I have a template variable, c.is_friend, that I would like to use to determine whether or not a class is applied. For example:

if c.is_friend is True
<a href="#" class="friend">link</a>

if c.is_friend is False
<a href="#">link</a>

Is there some way to do this inline, like:

<a href="#" ${if c.is_friend is True}class="friend"{/if}>link</a>

Or something like that?

like image 311
ensnare Avatar asked May 15 '10 21:05

ensnare


1 Answers

Python's normal inline if works:

<a href="#" ${'class="friend"' if c.is_friend else ''}>link</a>
like image 54
Jochen Ritzel Avatar answered Oct 11 '22 00:10

Jochen Ritzel