Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-24T09:15:00.727Z
Answers.Text: 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.
Answers.UserDisplayName: Jay
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-24T08:55:40.747Z
Answers.LastActivityDate: 2018-08-24T08:55:40.747Z
Answers.UserDisplayName: Urs
Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-24T10:16:48.527Z
Answers.Text: 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`?
Answers.UserDisplayName: Urs
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-24T11:19:46.910Z
Answers.Text: `entry.type` is passed automatically, yeah. I use `.twig` so I have Twig syntax highlighting in my IDE.
Answers.UserDisplayName: Jay
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-24T13:06:11.180Z
Answers.Text: oho, that's why it doesn't highlight with me!
Answers.UserDisplayName: Urs
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-29T10:49:19.260Z
Answers.Text: What IDE are you using?
Answers.UserDisplayName: Jay
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-29T14:13:32.527Z
Answers.Text: Im using vscode
Answers.UserDisplayName: Urs
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-24T09:23:50.837Z
Answers.LastActivityDate: 2018-08-24T09:23:50.837Z
Answers.UserDisplayName: Jay
Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-24T08:55:49.970Z
Answers.LastActivityDate: 2018-08-24T09:01:21.610Z
Answers.LastEditDate: 2018-08-24T09:01:21.610Z
Answers.UserDisplayName: phaetons
Body: <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>
  
Tags: <templating><extends>
Title: Templating basics: extend, include or use?
ThreadText: # 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
  
  ```
  <!DOCTYPE html>
  <html lang="de">
  
  {% include "pages/partials/_head.html" %}
  
  <body class="body">
  
  {% include "pages/partials/_header.html" %}
  
      <main class="main-wrapper">
           {% block content %} 
           MAIN CONTENT PLACEHOLDER
           {% endblock %}
      </main>
  
  {% include "pages/partials/_footer.html" %}
  {% include "pages/partials/_jsfooter.html" %}
  
  </body>
  </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.
  
  
  ---
  
  