Body: <p>To separate code and avoid duplication I am trying to split up recurring pieces of twig code into partials (think of a nav or a block of services for example).</p>
  
  <p>I tried using <code>include</code> but Craft requires me to register a template path. This is also stated in the <a href="https://docs.craftcms.com/v2/templating-overview.html#template-paths" rel="nofollow noreferrer">docs</a>.</p>
  
  <p>I'm not really sure this is the best way to do it since I would litter my "Sections" with "Singles" which would just function as nothing more include templates.</p>
  
  <p>For example in my <code>home.twig</code> I have the following piece of code:</p>
  
  <pre><code>&lt;div&gt;
      &lt;div class="container mx-auto px-4 pb-16"&gt;
          {% include 'pages/home/dienstenGrid.twig' %}
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Which would render the corresponding include template. But to be able to do this I have to register this "section"
  <a href="https://i.sstatic.net/7w2mW.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/7w2mW.png" alt="enter image description here"></a></p>
  
  <p>Something about this feels gross, and I was wondering if there's a better way to go about this issue. If <code>This is the way</code> I will use it this way (Star Wars: The Mandalorian pun intended)</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-12-02T14:48:07.257Z
Comments.Text: Couldn't you define a macro which returns your snippet for example and then simply call `{{ macros.dienstenGrid() }}` instead?
  
  Macros are defined in `/craft/templates/partials/macros.twig` as far as I remember
Comments.UserDisplayName: Campiotti
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-12-02T14:49:25.950Z
Comments.Text: That's what I was thinking, I found a thread on this stackexchange which pointed out macros. But it seems that macros are more used to create certain markup with variable inputs (like form tags) etc. But I might use macro's.
Comments.UserDisplayName: ArneDB
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-12-02T19:30:01.497Z
Comments.Text: Are you [extending a base layout template](https://twig.symfony.com/doc/3.x/tags/extends.html)?
Comments.UserDisplayName: Oli
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-12-02T20:18:04.170Z
Comments.Text: Yes I am. (I have to add more charachters to be able to comment)
Comments.UserDisplayName: ArneDB
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-12-03T00:05:32.457Z
Comments.Text: This shouldn't be the case, you can create any twig file without add an associate section to it. Just when you do that, it's a good idea to add ```_``` before the name. Just like ```_partials/home/dienstenGrid.twig```. Then this twig file/template is not visitable by just use the file path.
Comments.UserDisplayName: Parry Huang
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-12-03T09:49:45.623Z
Comments.Text: I've read your question 5 times but I still don't understand what you're expecting. Twig lets you include a template from anywhere in your templates directory. That included template is then responsible for outputting whatever you tell it to. There's no need to create singles for anything.
Comments.UserDisplayName: James Smith
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-12-03T18:26:53.697Z
Comments.Text: So I have done some more digging, and it's exactly like you guys say, it does work from anywhere in the template. The problem now is that I can't remember how I was doing it before. I'm trying to figure out what I was doing wrong so I could share it, but I forget. When I remember I will let you know. In any case I want to thank you for taking your time to answer my question. :S I'm sorry
Comments.UserDisplayName: ArneDB
Tags: <templating>
Title: Is there a way to include partials in Craft without setting a path?
ThreadText: # Is there a way to include partials in Craft without setting a path?
  
  (Asked by: username_0 on 2019-12-02)
  
  To separate code and avoid duplication I am trying to split up recurring pieces of twig code into partials (think of a nav or a block of services for example).
  
  I tried using `include` but Craft requires me to register a template path. This is also stated in the [docs](https://docs.craftcms.com/v2/templating-overview.html#template-paths).
  
  I'm not really sure this is the best way to do it since I would litter my "Sections" with "Singles" which would just function as nothing more include templates.
  
  For example in my `home.twig` I have the following piece of code:
  
  ```
  <div>
      <div class="container mx-auto px-4 pb-16">
          {% include 'pages/home/dienstenGrid.twig' %}
      </div>
  </div>
  
  ```
  
  Which would render the corresponding include template. But to be able to do this I have to register this "section"
  [![enter image description here](https://i.sstatic.net/7w2mW.png)](https://i.sstatic.net/7w2mW.png)
  
  Something about this feels gross, and I was wondering if there's a better way to go about this issue. If `This is the way` I will use it this way (Star Wars: The Mandalorian pun intended)
  
  **Tags:** templating
  
  > **Comments:**
  > **username_1**: Couldn't you define a macro which returns your snippet for example and then simply call `{{ macros.dienstenGrid() }}` instead?  Macros are defined in `/craft/templates/partials/macros.twig` as far as I remember  
  > **username_0**: That's what I was thinking, I found a thread on this stackexchange which pointed out macros. But it seems that macros are more used to create certain markup with variable inputs (like form tags) etc. But I might use macro's.  
  > **username_2**: Are you [extending a base layout template](https://twig.symfony.com/doc/3.x/tags/extends.html)?  
  > **username_0**: Yes I am. (I have to add more charachters to be able to comment)  
  > **username_3**: This shouldn't be the case, you can create any twig file without add an associate section to it. Just when you do that, it's a good idea to add ```_``` before the name. Just like ```_partials/home/dienstenGrid.twig```. Then this twig file/template is not visitable by just use the file path.  
  > **username_4**: I've read your question 5 times but I still don't understand what you're expecting. Twig lets you include a template from anywhere in your templates directory. That included template is then responsible for outputting whatever you tell it to. There's no need to create singles for anything.  
  > **username_0**: So I have done some more digging, and it's exactly like you guys say, it does work from anywhere in the template. The problem now is that I can't remember how I was doing it before. I'm trying to figure out what I was doing wrong so I could share it, but I forget. When I remember I will let you know. In any case I want to thank you for taking your time to answer my question. :S I'm sorry  
  
  ---
  
  ## 0 answers
  
  