Can someone explain me what does these "tal" commands do within my html tags? I learnt they are text attribute language commands but not clear on what they do.
<div tal:condition="myvar">
Your command returns:<br><tal:block tal:content="myvar"></tal:block>
</div>
Are they evaluating conditions? or placeholders? Please explain.
You're probably, hopefully familiar with "traditional" templating languages which look something like this:
<?php if ($myvar) : ?>
<div>
Your command returns:<br><?php echo $myvar; ?>
</div>
<?php endif; ?>
or:
{% if myvar %}
<div>
Your command returns:<br>{{ myvar }}
</div>
{% endif %}
or similar variations on that syntax. These languages simply output text and offer certain control structures, nothing more, nothing less.
TAL is HTML aware, it uses the HTML syntax as part of its own syntax.
<div tal:condition="myvar">
Your command returns:<br><tal:block tal:content="myvar"></tal:block>
</div>
It parses the HTML the same way a browser would, and uses the attributes on HTML elements to alter the template. In the above example, the entire div
would be shown or removed depending on the value of myvar
. It does the same thing as the other two examples above.
The advantage is twofold: