<p>Hmmm I think I've got it already:</p>

<p>_layout.html</p>

<pre><code>&lt;!DOCTYPE html&gt;
&lt;html lang="de"&gt;

{% include "pages/partials/_head.html" %}

&lt;body class="body"&gt;

{% include "pages/partials/_header.html" %}

    &lt;main class="main-wrapper"&gt;
         {% block content %} 
         MAIN CONTENT PLACEHOLDER
         {% endblock %}
    &lt;/main&gt;

{% include "pages/partials/_footer.html" %}
{% include "pages/partials/_jsfooter.html" %}

&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>and then in a page template, say front.html.</p>

<pre><code>{% extends "_layout" %} 

{% block content %} 
FRONT PAGE CONTENT
{% endblock %}
</code></pre>

CC BY-SA 4.0
2018-08-24T09:15:00.727Z
This is correct. However, I tend to put my `<head>` stuff straight in my base layout file (and the JS tags at the bottom). Because with an include it's just another bit of work for Craft to do that doesn't offer much benefit in development. Header and Footer files get worked on regularly during development that can be very large files, so it makes sense to pop them out.
Jay
CC BY-SA 4.0
2018-08-24T08:55:40.747Z
2018-08-24T08:55:40.747Z
Urs
<p>My setup regarding includes for templates is as follows:</p>

<p>I'll have a 'site' structure that looks at <code>/pages/_entry.twig</code> for it's template. But I'd have a range of entry types within this structure, for example:</p>

<ul>
<li>Homepage</li>
<li>Contact</li>
<li>News</li>
<li>Standard content</li>
</ul>

<p>Then my <code>/pages/_entry.twig</code> template looks like this:</p>

<pre><code>{% extends "_layout/base.twig" %}

{% block content %}
    {% include 'pages/' ~ entry.type %}
{% endblock %}
</code></pre>

<p>So the extending of my base template is sorted for all of them in one place (less repeated code ) and it just includes a file based on the entry type like so:</p>

<pre><code>/pages
  -- _entry.twig
  -- contact.twig
  -- homepage.twig
  -- news.twig
  -- standardContent.twig
</code></pre>

<p>And the entry type matches the file name so each entry type has it's own template automagically.</p>

CC BY-SA 4.0
2018-08-24T10:16:48.527Z
Is the value for `entry.type` passed in automatically? Where do you set it? And does it matter if the ending is `.twig` or `.html`?
Urs
CC BY-SA 4.0
2018-08-24T11:19:46.910Z
`entry.type` is passed automatically, yeah. I use `.twig` so I have Twig syntax highlighting in my IDE.
Jay
CC BY-SA 4.0
2018-08-24T13:06:11.180Z
oho, that's why it doesn't highlight with me!
Urs
CC BY-SA 4.0
2018-08-29T10:49:19.260Z
What IDE are you using?
Jay
CC BY-SA 4.0
2018-08-29T14:13:32.527Z
Im using vscode
Urs
CC BY-SA 4.0
2018-08-24T09:23:50.837Z
2018-08-24T09:23:50.837Z
Jay
<p>I use <code>extend</code> for different entry types.
So i have a master.html with the main html construct and includes page parts like header.html and footer.html</p>

<p>Then i have a standard.html that extends master.html and include the content templates.</p>

<p>Entry Types with different page structure like projects.html or gallery.html also extend master.html, but can have different content templates included.</p>

CC BY-SA 4.0
2018-08-24T08:55:49.970Z
2018-08-24T09:01:21.610Z
2018-08-24T09:01:21.610Z
phaetons
<p>I'm making first steps with Twig in Craft. Ok, it's a Twig question. But maybe you can give me the best practice for Craft?</p>

<p>I'm used to create templates Top-Down, like having a <code>master.html</code> template that includes <code>footer.html</code>, <code>header.html</code>, <code>content.html</code> etc. </p>

<p>Now Twig and with this Craft suggests I'd rather <code>extend</code> / inherit parent templates.</p>

<p>It looks like the easy way to start if I simply use <code>{% include "pages/partials/_head.html" %}</code> – but will this later on, when I start working on the content, somehow prohibit accessing the unique features of <code>extend</code>?</p>

<p>So: Should I grasp the logic of <code>extend</code> first or doesn't it matter?</p>

<templating><extends>
Templating basics: extend, include or use?
# Templating basics: extend, include or use?

(Asked by: username_0 on 2018-08-24)

I'm making first steps with Twig in Craft. Ok, it's a Twig question. But maybe you can give me the best practice for Craft?

I'm used to create templates Top-Down, like having a `master.html` template that includes `footer.html`, `header.html`, `content.html` etc.

Now Twig and with this Craft suggests I'd rather `extend` / inherit parent templates.

It looks like the easy way to start if I simply use `{% include "pages/partials/_head.html" %}` – but will this later on, when I start working on the content, somehow prohibit accessing the unique features of `extend`?

So: Should I grasp the logic of `extend` first or doesn't it matter?

**Tags:** templating, extends


---

## 3 answers

### Answer by username_0 on 2018-08-24. Score: 2 | Accepted answer

Hmmm I think I've got it already:
_layout.html



{% include "pages/partials/_head.html" %}



{% include "pages/partials/_header.html" %}

    
         {% block content %} 
         MAIN CONTENT PLACEHOLDER
         {% endblock %}
    

{% include "pages/partials/_footer.html" %}
{% include "pages/partials/_jsfooter.html" %}




and then in a page template, say front.html.
{% extends "_layout" %} 

{% block content %} 
FRONT PAGE CONTENT
{% endblock %}

> **Comments:**
> **username_1**: This is correct. However, I tend to put my `<head>` stuff straight in my base layout file (and the JS tags at the bottom). Because with an include it's just another bit of work for Craft to do that doesn't offer much benefit in development. Header and Footer files get worked on regularly during development that can be very large files, so it makes sense to pop them out.  

---

### Answer by username_1 on 2018-08-24. Score: 3

My setup regarding includes for templates is as follows:
I'll have a 'site' structure that looks at /pages/_entry.twig for it's template. But I'd have a range of entry types within this structure, for example:

Homepage
Contact
News
Standard content

Then my /pages/_entry.twig template looks like this:
{% extends "_layout/base.twig" %}

{% block content %}
    {% include 'pages/' ~ entry.type %}
{% endblock %}

So the extending of my base template is sorted for all of them in one place (less repeated code ) and it just includes a file based on the entry type like so:
/pages
  -- _entry.twig
  -- contact.twig
  -- homepage.twig
  -- news.twig
  -- standardContent.twig

And the entry type matches the file name so each entry type has it's own template automagically.

> **Comments:**
> **username_0**: Is the value for `entry.type` passed in automatically? Where do you set it? And does it matter if the ending is `.twig` or `.html`?  
> **username_1**: `entry.type` is passed automatically, yeah. I use `.twig` so I have Twig syntax highlighting in my IDE.  
> **username_0**: oho, that's why it doesn't highlight with me!  
> **username_1**: What IDE are you using?  
> **username_0**: Im using vscode  

---

### Answer by username_2 on 2018-08-24. Score: 2

I use `extend` for different entry types.
So i have a master.html with the main html construct and includes page parts like header.html and footer.html

Then i have a standard.html that extends master.html and include the content templates.

Entry Types with different page structure like projects.html or gallery.html also extend master.html, but can have different content templates included.


---

