Answers.Body: <p>First, I'd recommend that you have a total of 3 templates: <code>_child.html</code> for your child entries, <code>_parent.html</code> for your parent entries, and finally <code>_entry.html</code> which will basically work as a "controller" template (the only code contained in <code>_entry.html</code> should be the code that includes either the child or parent templates). You can, of course, name the templates whatever you want, but make sure that the Section's entry template is pointing to <code>_entry.html</code>.</p>
  
  <p>Then, put this in your <code>_entry.html</code> file:</p>
  
  <pre><code>{% switch entry.level %}
      {% case 1 %}
          {% include '_parent.html' %}
      {% default %}
          {% include '_child.html' %}
  {% endswitch %}
  </code></pre>
  
  <p>What the above does, is simply to look at the <code>entry.level</code> attribute, which returns the level your Structure entry is at. Top level entries are level 1, so for a simple 2-level Structure, this may work.</p>
  
  <p>If you need something more flexible, where a "parent" template should be loaded unrelated to levels but based on whether an entry has children or not, you could do something like this (also in <code>entry.html</code>):</p>
  
  <pre><code>{% if entry.children|length %}
      {% include '_parent.html' %}
  {% else %}
      {% include '_child.html' %}
  {% endif %}
  </code></pre>
  
  <p>Another option is to test for an entry's <code>parent</code> property instead (i.e. if an entry has a parent entry, it should load the child template):</p>
  
  <pre><code>{% if entry.parent %}
      {% include '_child.html' %}
  {% else %}
      {% include '_parent.html' %}
  {% endif %}
  </code></pre>
  
  <p>Note: You may need to correct the paths to your templates for the examples above – the <code>{% include %}</code> always works relative to your <code>/templates</code> folder, so if your templates actually live inside <code>/templates/news</code>, you'd have to use <code>{% include 'news/_parent.html' %}</code> (even if <code>_entry.html</code> and <code>_parent.html</code> is inside the same folder).</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-08-07T21:11:38.227Z
Answers.Text: How do I only show the children in `_parent.html`?
Answers.UserDisplayName: Jesse Winton
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-08-08T04:53:07.443Z
Answers.Text: You should probably create a new question for that, @JesseWinton.
Answers.UserDisplayName: Mats Mikkel Rummelhoff
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-08-07T09:42:21.513Z
Answers.LastActivityDate: 2016-08-07T09:42:21.513Z
Answers.UserDisplayName: Mats Mikkel Rummelhoff
Body: <p>So, I'm newer to Craft, and so I need to figure out the best way to set up a portfolio page with child entries. I've set up a structure, but I need the parent page to load a different template than <code>_entry.html</code>. I still haven't been able to figure out a good solution for this, so any help would be great.</p>
  
  <p>Thanks!</p>
  
Tags: <templating><routing>
Title: How to load a different template for parent page
ThreadText: # How to load a different template for parent page
  
  (Asked by: username_0 on 2016-08-06)
  
  So, I'm newer to Craft, and so I need to figure out the best way to set up a portfolio page with child entries. I've set up a structure, but I need the parent page to load a different template than `_entry.html`. I still haven't been able to figure out a good solution for this, so any help would be great.
  
  Thanks!
  
  **Tags:** templating, routing
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-08-07. Score: 7 | Accepted answer
  
  First, I'd recommend that you have a total of 3 templates: `_child.html` for your child entries, `_parent.html` for your parent entries, and finally `_entry.html` which will basically work as a "controller" template (the only code contained in `_entry.html` should be the code that includes either the child or parent templates). You can, of course, name the templates whatever you want, but make sure that the Section's entry template is pointing to `_entry.html`.
  
  Then, put this in your `_entry.html` file:
  
  ```
  {% switch entry.level %}
      {% case 1 %}
          {% include '_parent.html' %}
      {% default %}
          {% include '_child.html' %}
  {% endswitch %}
  
  ```
  
  What the above does, is simply to look at the `entry.level` attribute, which returns the level your Structure entry is at. Top level entries are level 1, so for a simple 2-level Structure, this may work.
  
  If you need something more flexible, where a "parent" template should be loaded unrelated to levels but based on whether an entry has children or not, you could do something like this (also in `entry.html`):
  
  ```
  {% if entry.children|length %}
      {% include '_parent.html' %}
  {% else %}
      {% include '_child.html' %}
  {% endif %}
  
  ```
  
  Another option is to test for an entry's `parent` property instead (i.e. if an entry has a parent entry, it should load the child template):
  
  ```
  {% if entry.parent %}
      {% include '_child.html' %}
  {% else %}
      {% include '_parent.html' %}
  {% endif %}
  
  ```
  
  Note: You may need to correct the paths to your templates for the examples above – the `{% include %}` always works relative to your `/templates` folder, so if your templates actually live inside `/templates/news`, you'd have to use `{% include 'news/_parent.html' %}` (even if `_entry.html` and `_parent.html` is inside the same folder).
  
  > **Comments:**
  > **username_0**: How do I only show the children in `_parent.html`?  
  > **username_1**: You should probably create a new question for that, @username_0.  
  
  ---
  
  