{"result":{"depiction_url":null,"edges":{"hasreference":{"objects":[{"created":"2026-10-07T11:13:38Z","object_id":{"id":2943,"is_a":["text","documentation","developerguide"],"name":"developer_template_components","title":{"_type":"trans","tr":{"en":"Reuse markup with includes and categories"}},"uri":"https:\/\/zotonic.com\/id\/2943"},"seq":1},{"created":"2026-10-07T11:13:38Z","object_id":{"id":2325,"is_a":["text","documentation","cookbook"],"name":null,"title":{"_type":"trans","tr":{"en":"Render template values safely"}},"uri":"https:\/\/zotonic.com\/id\/2325"},"seq":2},{"created":"2026-10-07T11:13:38Z","object_id":{"id":1577,"is_a":["text","documentation","cookbook"],"name":"doc_cookbook_overriding","title":{"_type":"trans","tr":{"en":"Override a module template"}},"uri":"https:\/\/zotonic.com\/id\/1577"},"seq":3}],"predicate":{"id":2774,"is_a":["meta","predicate"],"name":"hasreference","title":{"_type":"trans","tr":{"en":"Documentation reference"}},"uri":"https:\/\/zotonic.com\/id\/hasreference"}},"references":{"objects":[{"created":"2020-05-30T05:48:08Z","object_id":{"id":1278,"is_a":["text","documentation","reference","model"],"name":"doc_model_model_rsc","title":"rsc","uri":"https:\/\/zotonic.com\/id\/1278"},"seq":1000000},{"created":"2020-05-30T05:48:08Z","object_id":{"id":1768,"is_a":["text","documentation","reference","model"],"name":"doc_model_model_site","title":"site","uri":"https:\/\/zotonic.com\/id\/1768"},"seq":1000000},{"created":"2020-05-30T05:48:08Z","object_id":{"id":1534,"is_a":["text","documentation","reference","controller"],"name":"doc_controller_controller_page","title":"controller_page","uri":"https:\/\/zotonic.com\/id\/1534"},"seq":1000000},{"created":"2020-05-30T05:48:08Z","object_id":{"id":1279,"is_a":["text","documentation"],"name":"doc_glossary","title":"Glossary","uri":"https:\/\/zotonic.com\/id\/1279"},"seq":1000000}],"predicate":{"id":332,"is_a":["meta","predicate"],"name":"references","title":{"_type":"trans","tr":{"en":"References"}},"uri":"https:\/\/zotonic.com\/id\/references"}},"refers":{"objects":[{"created":"2026-10-07T11:13:03Z","object_id":{"id":1325,"is_a":["text","documentation","reference","template_tag"],"name":"doc_template_tag_tag_catinclude","title":"catinclude","uri":"https:\/\/zotonic.com\/id\/1325"},"seq":1000000},{"created":"2026-10-07T11:13:03Z","object_id":{"id":1326,"is_a":["text","documentation","reference","template_tag"],"name":"doc_template_tag_tag_include","title":"include","uri":"https:\/\/zotonic.com\/id\/1326"},"seq":1000000},{"created":"2026-10-07T11:13:03Z","object_id":{"id":1348,"is_a":["text","documentation","reference","template_tag"],"name":"doc_template_tag_tag_overrules","title":"overrules","uri":"https:\/\/zotonic.com\/id\/1348"},"seq":1000000},{"created":"2026-10-07T11:13:03Z","object_id":{"id":1461,"is_a":["text","documentation","reference","template_filter"],"name":"doc_template_filter_filter_escape","title":"escape","uri":"https:\/\/zotonic.com\/id\/1461"},"seq":1000000},{"created":"2026-10-07T11:13:03Z","object_id":{"id":1536,"is_a":["text","documentation","developerguide"],"name":"doc_developerguide_access_control","title":{"_type":"trans","tr":{"en":"Keep permission checks at the boundary"}},"uri":"https:\/\/zotonic.com\/id\/1536"},"seq":1000000},{"created":"2026-10-07T11:13:03Z","object_id":{"id":2941,"is_a":["text","documentation","developerguide"],"name":"developer_template_selection","title":{"_type":"trans","tr":{"en":"Find the template used by a page"}},"uri":"https:\/\/zotonic.com\/id\/2941"},"seq":1000000},{"created":"2026-10-07T11:13:03Z","object_id":{"id":2960,"is_a":["text","documentation","developerguide"],"name":"developer_model_api","title":{"_type":"trans","tr":{"en":"Expose data through a model"}},"uri":"https:\/\/zotonic.com\/id\/2960"},"seq":1000000}],"predicate":{"id":2409,"is_a":["meta","predicate"],"name":"refers","title":{"_type":"trans","tr":{"en":"Refers"}},"uri":"https:\/\/zotonic.com\/id\/refers"}},"subject":{"objects":[{"created":"2026-10-07T11:13:38Z","object_id":{"id":2554,"is_a":["categorization","keyword","keyword_information_type"],"name":"zotonic_topic_how_to_guide","title":"How-to guide","uri":"https:\/\/zotonic.com\/id\/2554"},"seq":1},{"created":"2026-10-07T11:13:38Z","object_id":{"id":2563,"is_a":["categorization","keyword","keyword_audience"],"name":"zotonic_topic_frontend_developer","title":"Frontend developer","uri":"https:\/\/zotonic.com\/id\/2563"},"seq":2},{"created":"2026-10-07T11:13:38Z","object_id":{"id":2620,"is_a":["categorization","keyword","keyword_architecture"],"name":"zotonic_topic_template","title":"Template","uri":"https:\/\/zotonic.com\/id\/2620"},"seq":3},{"created":"2026-10-07T11:13:38Z","object_id":{"id":2641,"is_a":["categorization","keyword","keyword_task"],"name":"zotonic_topic_render","title":"Render","uri":"https:\/\/zotonic.com\/id\/2641"},"seq":4},{"created":"2026-10-07T11:13:38Z","object_id":{"id":2685,"is_a":["categorization","keyword","keyword_quality"],"name":"zotonic_topic_security","title":"Security","uri":"https:\/\/zotonic.com\/id\/2685"},"seq":5}],"predicate":{"id":308,"is_a":["meta","predicate"],"name":"subject","title":{"_type":"trans","tr":{"en":"Keyword"}},"uri":"http:\/\/purl.org\/dc\/elements\/1.1\/subject"}}},"id":1860,"is_a":["text","documentation","developerguide"],"links":[{"rel":"self","target":"https:\/\/zotonic.com\/.zotonic\/websub\/topic\/1860"},{"rel":"hub","target":"https:\/\/zotonic.com\/.zotonic\/websub"}],"medium":null,"medium_url":null,"name":"doc_bestpractices_templates","page_url":{"en":"https:\/\/zotonic.com\/docs\/1860\/reuse-markup-with-includes-and-categories","x-default":"https:\/\/zotonic.com\/docs\/1860\/reuse-markup-with-includes-and-categories"},"preview_url":null,"resource":{"body":{"_type":"trans","tr":{"en":"<pre class=\"notranslate\"><code class=\"notranslate language-django\">{% include &quot;_garden_card.tpl&quot; id=id %}\n<\/code><\/pre>\n<p>Inside the partial, read the resource using <code>m.rsc[id]<\/code>. Keep the partial focused on one component so another page can reuse it without inheriting unrelated page behavior.<\/p>\n<p>Use a category include when the representation depends on the resource&#39;s category:<\/p>\n<pre class=\"notranslate\"><code class=\"notranslate language-django\">{% catinclude &quot;_garden_card.tpl&quot; id %}\n<\/code><\/pre>\n<p>Provide a generic fallback and add category-specific variants when their markup differs. Use the template selection tools to check which variant wins for the resource. See <a href=\"\/id\/1326\" class=\"doc-reference doc-reference-tag\"><code>tag#include<\/code><\/a>, <a href=\"\/id\/1325\" class=\"doc-reference doc-reference-tag\"><code>tag#catinclude<\/code><\/a>, and <a href=\"\/id\/2941\">Find the template used by a page<\/a>.<\/p>\n<p>For the example above, save the fallback as <code>priv\/templates\/_garden_card.tpl<\/code>. An event-specific version is <code>_garden_card.event.tpl<\/code>. A resource named <code>garden_open_day<\/code> can override both with <code>_garden_card.name.garden_open_day.tpl<\/code>. Test an event and an ordinary text resource: the latter should still use the fallback.<\/p>\n<h2>Display values safely<\/h2>\n<p>Resource properties read through <code>m.rsc<\/code> follow Zotonic&#39;s content handling. Query arguments and values returned by custom models do not automatically have the same guarantees.<\/p>\n<p>Escape plain text from those sources:<\/p>\n<pre class=\"notranslate\"><code class=\"notranslate language-django\">&lt;p&gt;{{ q.term|escape }}&lt;\/p&gt;\n<\/code><\/pre>\n<p>Do not mark arbitrary user input as safe HTML. Decide at the model or content boundary whether a field contains text, sanitized HTML, a URL, or another type. Keep that decision consistent across templates and API responses.<\/p>\n<p>When a value renders unexpectedly, inspect its type and translation behavior before applying more filters. See <a href=\"\/id\/1461\" class=\"doc-reference doc-reference-filter\"><code>filter#escape<\/code><\/a>, <a href=\"\/id\/2960\">Expose data through a model<\/a>, and <a href=\"\/id\/1536\">Keep permission checks at the boundary<\/a>.<\/p>\n<h2>Override a module template<\/h2>\n<p>Find the active template and its path relative to <code>priv\/templates<\/code>. Create the same relative path in your site or another active module with a higher selection priority.<\/p>\n<p>Copy only the structure you need to change. When the original template offers blocks, extend it using the supported inheritance pattern rather than duplicating a large file. Check <a href=\"\/id\/1348\" class=\"doc-reference doc-reference-tag\"><code>tag#overrules<\/code><\/a> for extending the next matching template.<\/p>\n<p>Load the affected page and inspect the selected template again. A successful compile does not prove that your override is used. Test neighboring categories and languages if the original template serves more than one page type.<\/p>\n<p>For example, place this in the same relative template path as the template being overridden:<\/p>\n<pre class=\"notranslate\"><code class=\"notranslate language-django\">{% overrules %}\n{% block content %}\n    {% inherit %}\n    &lt;p&gt;{_ Contact us for more information. _}&lt;\/p&gt;\n{% endblock %}\n<\/code><\/pre>\n<p>Use a block that exists in the original. <code>{% inherit %}<\/code> keeps its content; omit it only when replacing that entire block is intentional. This is especially important for admin panels, where copying a small fragment over a large panel can remove controls.<\/p>"}},"category_id":{"id":317,"is_a":["meta","category"],"name":"developerguide","title":"Developer guide","uri":"https:\/\/zotonic.com\/id\/developerguide"},"content_group_id":{"id":339,"is_a":["meta","content_group"],"name":"default_content_group","title":{"_type":"trans","tr":{"en":"Default Content Group"}},"uri":"https:\/\/zotonic.com\/id\/default_content_group"},"created":"2020-05-30T05:47:41Z","creator_id":{"id":336,"is_a":["person","robot"],"name":"gitbot","title":"Git","uri":"https:\/\/zotonic.com\/id\/336"},"doc_editorial_bundle":true,"doc_editorial_edges":{"hasreference":[1577,2325,2943],"subject":[2554,2563,2620,2641,2685]},"github_url":"https:\/\/github.com\/zotonic\/zotonic\/tree\/master\/doc\/best-practices\/templates.rst","is_authoritative":true,"is_dependent":false,"is_featured":false,"is_protected":false,"is_published":true,"is_unfindable":false,"language":["en"],"modified":"2026-10-07T20:45:38Z","modifier_id":{"id":1,"is_a":["person"],"name":"administrator","title":"Site Administrator","uri":"https:\/\/zotonic.com\/id\/1"},"name":"doc_bestpractices_templates","pivot_geocode":null,"pivot_location_lat":null,"pivot_location_lng":null,"privacy":0,"publication_end":"9999-06-01T00:00:00Z","publication_start":"2022-02-15T10:01:27Z","slug":"reuse-markup-with-includes-and-categories","summary":{"_type":"trans","tr":{"en":"Extract repeated markup into a partial and pass its inputs explicitly."}},"title":{"_type":"trans","tr":{"en":"Reuse markup with includes and categories"}},"title_slug":{"_type":"trans","tr":{"en":"reuse-markup-with-includes-and-categories"}},"tz":"UTC","uri":null,"version":45,"visible_for":0},"uri":"https:\/\/zotonic.com\/id\/1860","uri_template":"https:\/\/zotonic.com\/id\/:id","websub":{"hub":"https:\/\/zotonic.com\/.zotonic\/websub","topic":"https:\/\/zotonic.com\/.zotonic\/websub\/topic\/1860"}},"status":"ok"}