Grantlee  5.1.0
Builtin tags and filters.

Tags and filters ported from Django

See the Builtins documentation for Django 1.1 for an overview of the builtin tags and filters available in Grantlee. Almost all tags and filter in django are available in Grantlee. Exceptions are the url tag, because Grantlee does not have a views system. Additionally the ssi tag is disabled because of potential security risks. The dictdort, dictsortreversed, filesizeformat, iriencode, phone2numeric, pluralize, pprint, title, truncatewords_html, urlencode, urlize and urlizetrunc filters have not yet been ported due to time constraints.

Additional tags available in Grantlee

Grantlee also provides some extra tags not available in DJango.

media_finder

Queries Grantlee for a complete URL, given a target name.

This tag can typically be used to insert a URL for an image, external script or CSS file, or other external media.

<img src="{% media_finder "someimage.png" %}" />

The media_finder tag retrieves the result through Engine::mediaUri, which in turn queries the TemplateLoaders for the URL to return via the TemplateLoader::getMediaUri interface.

It is possible to configure whether absolute or relative urls are created by using the Context::setUrlType method. If the path to external media is not the same as the path to the template, the Context::setRelativeMediaPath method can be used to specify a relative base path. For example, if creating a template /home/user/myoutput.html which references someimage.png, the path "myoutput_media/" can be set so that the {% media_finder %} puts the path myoutput_media/someimage.png into the template. This way the output and the media it references are portable together.

It is the responsibility of the caller to copy the media to the /home/user/myoutput_media/ directory.

with media_prefix defined to nothing when creating output with absolute urls, and something like "media/" if creating output with relative urls and external media should be available in the media/ subdirectory.

range

Loops over a range in a manner similar to the python builtin of the same name.

Create a list from 0 to 5:

<ul>
{% range 5 as num %}
<li>{{ num }}
{% endrange %}
</ul>

Create a list from 5 to 10:

<ul>
{% range 5 10 as num %}
<li>{{ num }}
{% endrange %}
</ul>

Create a list from 5 to 50 with a step of 5:

<ul>
{% range 5 50 5 as num %}
<li>{{ num }}
{% endrange %}
</ul>

The range tag can also be used without arguments:

{% range rating %}
<img src="{% media_finder "star.png" %}" />
{% endrange %}