Craft CMS Stack Exchange is a question and answer site for administrators, end users, developers and designers for Craft CMS. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 7 down vote accepted

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.

share|improve this answer
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 Jul 25 '14 at 16:21

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.