The templating language used by pythonite is a HTML attribute language extension using the "py" namespace.
Example:
<h1 py:sub="document.title"> ... </h1>
tag attributes
- py:sub="expr"
- Substitute the content between surrounding tags with the value of expr
- py:rep="expr"
- Like py:sub but replace also the surrounding tags
- py:attr="expr"
- Substitute the value of the preceding attribute
- py:set="var expr"
- Set a variable to expr
<b py:sub="1">0</b> => <b>1</b> <b py:rep="1">0</b> => 1 <a href="page.htm" py:attr="'/'">link</a> => <a href="/">link</a>
conditional change
- "if condition"
- keep the block only if condition is true
- if condition: change
- change the block content only if condition is true
<b py:sub="if False">0</b> => <b py:sub="if True">0</b> => <b>0</b> <b py:sub="if False: 1">0</b> => <b>0</b> <b py:sub="if True: 1">0</b> => <b>1</b> <b py:rep="if False">0</b> => <b py:rep="if True">0</b> => 0 <b py:rep="if False: 1">0</b> => 0 <b py:rep="if True: 1">0</b> => 1
block repetitions
- "for var in list"
- repeat the block for each var in list
- "for var in list: change"
- change the block content for each var in list
<b py:sub="for i in range(3)">x</b> => <b>x</b><b>x</b><b>x</b> <b py:rep="for i in range(3)">x</b> => xxx <b py:sub="for i in range(3): i">x</b> => <b>0</b><b>1</b><b>2</b> <b py:rep="for i in range(3): i+1">x</b> => 123