how to do some backward modifying

10 views
Skip to first unread message

Jinghui Niu

unread,
Mar 25, 2016, 11:05:13 PM3/25/16
to Mako Templates for Python
Is there a way in Mako allowing me to do some backward modifying according to some conditionals that is after where I want the modification goes?\

Here is my example:

<%def name="expand_navigationTree(parentNode)">
 
% for item_tuple in parentNode:
      <li>
        ${item_tuple[0]}
 
% if item_tuple[1] is not None: ## containing sub-menu
     
<ul class="submenu is-hidden">
        $
{expand_navigationTree(item_tuple[1])}
     
</ul>
  % endif
      </
li>
 
% endfor
</%def>

In this example, I'd like to add a 
<span class='fa fa-caret-down' style='float: right'></span>

if the
if item_tuple[1] is not None

condition evaluates to True.


As you can see, it's very awkward. I don't know if Mako allows me to do this kind of thing? 

Many thanks.

Jinghui Niu

unread,
Mar 25, 2016, 11:07:14 PM3/25/16
to Mako Templates for Python
Oh, I forgot to clarify this. In the example that I gave, I'd like that <span> portion to go BEFORE the submenu, something that jQuery prepend method does. Sorry for not pointing out in my last post.

Jonathan Vanasco

unread,
Mar 26, 2016, 2:41:26 AM3/26/16
to Mako Templates for Python
Make just renders text/html; jquery does DOM manipulation.

You need to write another "if" statement, or render the text in another way.
Reply all
Reply to author
Forward
0 new messages