Templates are usually made up of other templates, especially if you want to re-use page/document components. Proton supports an include function to embed one template inside another.
For example, a fragment of a template (include2.xhtml) containing 2 paragraphs of text…
<div>
<p eid="para1">PARA 1 TEXT</p>
<p eid="para2">PARA 2 TEXT</p>
</div>
…can be embedded in another template (include1.xhtml)…
<body>
<h1 eid="title">PAGE TITLE GOES HERE</h1>
<div eid="includedcontent">
INCLUDED CONTENT GOES HERE
</div>
</body>
…and then populated with data, using the following snippet of code:
tmp = self.templates['include1.xhtml']
tmp.setelement('title', 'Page Title')
tmp.include('includedcontent', 'include2.xhtml')
tmp.setelement('para1', 'First paragraph of text')
tmp.setelement('para2', 'Second paragraph of text')
On the ‘syntactic sugar front’, as an alternative to the more explicit repeat function (for repeating elements in the output), Proton supports setting lists of values rather than single-values. Consider the template:
<ul>
<li rid="list-item" eid="list-item">LIST ITEMS</li>
</ul>
The list can be populated without having to explicitly call repeat, using the following code snippet:
lst = [ 'a', 'b', 'c', 'd', 'e', 'f', 'g' ]
tmp.setelement('list-item', lst)
If your objects are decorated with properties (@property), then Proton also supports automatically setting the values in the page, using the convention of id followed by colon followed by property. For example, using the following template:
<dl>
<dt>X Value</dt>
<dd eid="prop:x">prop x here</dd>
<dt>Y Value</dt>
<dd eid="prop:y">prop y here</dd>
</dl>
A class Temp, with properties x and y can be set in the template, with the name prop and the values will be automatically populated.
class Temp(object):
def __init__(self, x, y):
self._x = x
self._y = y
@property
def x(self):
return self._x
@property
def y(self):
return self._y
t = Temp('100', '500')
tmp.setelement('prop', t)



