# fragment

Source: https://zotonic.com/docs/2505/fragment

URI: https://zotonic.com/id/2505

Language: en



::: {.aside}
See also

<a href="/id/doc_template_tag_tag_use" class="doc-reference doc-reference-tag"><code>tag#use</code></a>, <a href="/id/doc_template_tag_tag_useblock" class="doc-reference doc-reference-tag"><code>tag#useblock</code></a>, <a href="/id/doc_template_tag_tag_block" class="doc-reference doc-reference-tag"><code>tag#block</code></a>, <a href="/id/doc_template_tag_tag_extends" class="doc-reference doc-reference-tag"><code>tag#extends</code></a> and <a href="/id/doc_template_tag_tag_overrules" class="doc-reference doc-reference-tag"><code>tag#overrules</code></a>.
:::

Define a named reusable template fragment.

A fragment is a named piece of template output that can be reused with the <a href="/id/doc_template_tag_tag_use" class="doc-reference doc-reference-tag"><code>tag#use</code></a> and <a href="/id/doc_template_tag_tag_useblock" class="doc-reference doc-reference-tag"><code>tag#useblock</code></a> tags.

Fragments can also contain <a href="/id/doc_template_tag_tag_block" class="doc-reference doc-reference-tag"><code>tag#block</code></a> definitions. Those blocks can be addressed from a <a href="/id/doc_template_tag_tag_useblock" class="doc-reference doc-reference-tag"><code>tag#useblock</code></a> call, similar to <a href="/id/doc_template_tag_tag_compose" class="doc-reference doc-reference-tag"><code>tag#compose</code></a>.

Example:

```django
{% fragment answer_row %}
    <div class="row">
        <label>{{ label }}</label>
        <span>{{ value }}</span>
    </div>
{% endfragment %}

{% use answer_row label="Email" value=user.email %}
{% use answer_row with label="Phone" value=user.phone %}
```

The fragment definition itself does not render any output at the place where it is defined.

Fragments are available in the template where they are defined, and in templates that use <a href="/id/doc_template_tag_tag_extends" class="doc-reference doc-reference-tag"><code>tag#extends</code></a> or <a href="/id/doc_template_tag_tag_overrules" class="doc-reference doc-reference-tag"><code>tag#overrules</code></a> with that template.

Fragments use the current template context. Extra variables can be supplied by the <a href="/id/doc_template_tag_tag_use" class="doc-reference doc-reference-tag"><code>tag#use</code></a> or <a href="/id/doc_template_tag_tag_useblock" class="doc-reference doc-reference-tag"><code>tag#useblock</code></a> tags.

License: 

Attribution: 

Related resources: https://zotonic.com/api/agent/related/2505?language=en


## API access

- [API help](<https://zotonic.com/api-help>)
- [OpenAPI specification](<https://zotonic.com/openapi.json>)
- [This resource as JSON](<https://zotonic.com/api/agent/resource/2505?language=en>)
