===========
Reuse Parts
===========
Jinja allows to move often used parts into external files.
This is an addition to the `template inheritance`_ system.
Predefined Blocks
=================
You can predefine blocks for later usage using the tag ``{% prepare %}``::
{% prepare "box" %}
this is the default box
{% endprepare %}
{% prepare "dialog" accepting title, content %}
{{ title|escapexml }}
{% if content" %}
{{ content }}
{% endif %}
{% endprepare %}
You can now display that block everywhere on the same file as long as
the block was prepared above the first usage::
{% for user in users %}
- {{ user.username }}
{% if user.description %}
{% call dialog, "User Details", user.description %}
{% endif %}
{% endfor %}
{% call "box" %}
Include Files
=============
You can use ``{% include %}`` to include files which are loadable by the
current loader. That means you include it like you would extend from it::
Hello World
{% include "parts/introtext" %}
Requiring Files
===============
``{% require %}`` works like ``{% include %}`` but doesn't return the
output. This can be useful for loading `Predefined Blocks`_ or if you want to
write the rendered file into a variable::
{% require "myblocks" %}
{% require "parts/introtext" as introtext %}
Hello World
{% call "divbox", "intro", introtext %}
The first require will load "myblocks" and return nothing, the second one
will load "parts/introtext" and save the output in a variable "introtext".
Additionally require will only load blocks one time which means fastens up
jinja a lot when using the same included file on more than one page.
.. _template inheritance: inheritance.txt