Built in template functions

defined(key)

Return True if a variable named key is defined, else False.

<!--
Will only produce output if a variable 'message' has been defined
-->
<h1 py:if="defined('message')">$message</h1>

value_of(key, [default])

Return the value of the variable named key if it exists, else default.

<!--! Outputs 'today it is rainy' -->
<div py:with="weather='rainy'">today it is ${value_of('weather', 'sunny')}</div>

<!--! Outputs 'today it is sunny' -->
<div>today it is ${value_of('weather', 'sunny')}</div>

super()

Render the parent block when using template inheritance. This function is only available inside Piglet py:block directives.

Example:

<!-- file: layout.html -->

<section py:block="content">
    <p>Eat more biscuits</p>
</section>
<!-- file: index.html -->
<py:extends href="layout.html">
    <section py:block="content">
        <p>Drink more tea</p>
        <p>${super()}</p>
    </section>
</py:extends>

This would produce the following output:

<section>
    <p>Drink more tea</p>
    <p>Eat more biscuits</p>
</section>