<p>If your template is <em>_example.html</em>, you include like this:</p>

<pre><code>{% include '_example.html' %}
</code></pre>

<p>It also works to have a template in a directory that starts with an underscore. So you could name the directory <em>_includes</em>, name the template in there <em>example.html</em> and include it like this:</p>

<pre><code>{% include '_includes/example.html' %}
</code></pre>

<p>Either way, the template can't be accessed directly.</p>

CC BY-SA 3.0
2014-07-25T16:21:46.143Z
Ah, I missed the point (facepalm) Since you also need to adjust the include I thought you could still access the template with the underscore added. But then it's blocked
noregt
CC BY-SA 3.0
2014-07-25T15:47:52.533Z
2014-07-25T15:47:52.533Z
Marion Newlevant
<p>How can I prevent people accessing templates directly that are only used as includes for instance?</p>

<p>I read that I could add an underscore ie _example.html,but then the include stops working.</p>

<templating><hiding>
How to block direct access to templates (hiding templates)
# How to block direct access to templates (hiding templates)

(Asked by: username_0 on 2014-07-25)

How can I prevent people accessing templates directly that are only used as includes for instance?

I read that I could add an underscore ie \_example.html,but then the include stops working.

**Tags:** templating, hiding

---

## 1 answers

### Answer by username_1 on 2014-07-25. Score: 8 | Accepted answer

If your template is _example.html, you include like this:
{% include '_example.html' %}

It also works to have a template in a directory that starts with an underscore. So you could name the directory _includes, name the template in there example.html and include it like this:
{% include '_includes/example.html' %}

Either way, the template can't be accessed directly.

> **Comments:**
> **username_0**: Ah, I missed the point (facepalm) Since you also need to adjust the include I thought you could still access the template with the underscore added. But then it's blocked  

---

