Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can my chameleon template accept message flashes from the pyramid framework?

I'm learning pyramid and it seems they are trying to get people to use chameleon instead of mako so I thought I'd give chameleon a chance. I like it so far and I can do basic things in the template such as if and for loops but I'm not sure how to get message flashes to appear.

In the pyramid tutorial they do this in a todo list but in the wiki example they do not. According to the instructions about sessions and using the todolist tutorial as a example I have been able to get my app to create messages but I'm unable to receive them in my template. In a nutshell, I'm wondering if chameleon has a equivalent of this mako code:

  % if request.session.peek_flash():
  <div id="flash">
    <% flash = request.session.pop_flash() %>
    % for message in flash:
    ${message}<br>
    % endfor
  </div>
  % endif
like image 927
Lostsoul Avatar asked Jun 26 '12 03:06

Lostsoul


1 Answers

The (untested) equivalent in chameleon is:

<div id="flash" tal:condition="request.session.peek_flash()">
  <span tal:omit-tag="" 
        tal:repeat="message request.session.pop_flash()">
      ${message}<br>
  </span>
</div>

The tal:omit-tag attribute is optional; it drops the <span> tag from the output, as it is only used as dummy tag to attach the repeat to. By dropping it the output of the Chameleon template will match the Mako example.

See the Chameleon documentation for an introduction and full specification of how the template language works.

like image 195
Martijn Pieters Avatar answered Oct 01 '22 19:10

Martijn Pieters