# useblock

Source: https://zotonic.com/docs/2509/useblock

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

Language: en



::: {.aside}
See also

<a href="/id/doc_template_tag_tag_fragment" class="doc-reference doc-reference-tag"><code>tag#fragment</code></a> and <a href="/id/doc_template_tag_tag_use" class="doc-reference doc-reference-tag"><code>tag#use</code></a>.
:::

Render a named <a href="/id/doc_template_tag_tag_fragment" class="doc-reference doc-reference-tag"><code>tag#fragment</code></a>, pass it enclosed body content, and optionally override its named blocks.

The `useblock` tag is like <a href="/id/doc_template_tag_tag_use" class="doc-reference doc-reference-tag"><code>tag#use</code></a>, but also passes the enclosed rendered content to the fragment in the special variable `_body`.

If the fragment contains named <a href="/id/doc_template_tag_tag_block" class="doc-reference doc-reference-tag"><code>tag#block</code></a> definitions, then the `useblock` body can also define blocks with the same names. Those caller blocks override the fragment’s block definitions, similar to <a href="/id/doc_template_tag_tag_compose" class="doc-reference doc-reference-tag"><code>tag#compose</code></a>.

Example:

```django
{% fragment panel %}
    <section class="panel">
        <h2>{{ title }}</h2>
        <div class="panel-body">{{ _body }}</div>
    </section>
{% endfragment %}

{% useblock panel title="Summary" %}
    <p>Hello world</p>
{% enduseblock %}
```

Example with block overrides:

```django
{% fragment panel %}
    <section>
        {% block title %}Default title{% endblock %}
        <div>{{ _body }}</div>
    </section>
{% endfragment %}

{% useblock panel %}
    {% block title %}Custom title{% endblock %}
    Body text
{% enduseblock %}
```

::: {.note title="Note"}
Like the <a href="/id/doc_template_tag_tag_include" class="doc-reference doc-reference-tag"><code>tag#include</code></a> tag, the `with` keyword is optional:

```django
{% useblock panel title="Summary" %}
    <p>Hello world</p>
{% enduseblock %}

{% useblock panel with title="Summary" %}
    <p>Hello world</p>
{% enduseblock %}
```
:::

License: 

Attribution: 

Related resources: https://zotonic.com/api/agent/related/2509?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/2509?language=en>)
