I am a java programmer learning python / jinja .
My biggest beef with jinja2 macros is limiting one caller (). for example, I could do the following in jsp2 tags:
tag def:
<% attribute name="title" fragment="true"> <div class='title'>${title}</div> <div class='body'><jsp:doBody/></div>
using:
<myTag> <jsp:attribute name='title'> <c:if test='${blah}'>This is only here sometimes</c:if> </jsp:attribute> <jsp:body> <c:if test='${something}'>some dynamic content</c:if> </jsp:body> </myTag>
what I want stress is that both the contents of the body and the title attribute are dynamic . In addition, there are no hackers to set variables for dynamic content and transfer them.
now look at a jinja macro that does the same thing:
{% macro myTag(title='', caller) -%} <div class='title'>{{ title }}</div> <div class='body'>{{ caller() }}</div> {%- endmacro %}
but wait! I cannot easily put dynamic content in the title attribute!
{% call myTag(title='imagine putting some content here that involves 5 loops, 4 ifs and whatnot?') %} {% if something %}some dynamic content{% endif %} {% endcall %}
Is this a problem with being a newbie or is it a lack of genie?
source share