Answers.Body: <p>When you call Craft's <a href="https://craftcms.com/classreference/services/TemplatesService#getTwig-detail" rel="nofollow"><code>TemplatesService-&gt;getTwig()</code></a>  (<code>craft()-&gt;templates-&gt;getTwig()</code>), the first parameter you can pass in is your custom template loader classname.</p>
  
  <p>i.e. <code>craft()-&gt;templates-&gt;getTwig('\My\Awesome\Plugin\TemplateLoader, array('my' =&gt; 'options')</code></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-09-05T09:43:50.723Z
Answers.Text: Many thanks @brad that is exactly what I was looking for! Top stuff.
Answers.UserDisplayName: Mark Perkins
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-09-04T18:38:40.373Z
Answers.Text: I'm trying to do the same thing as Mark, but am struggling to see how this fits into the plugin architecture. What do I need to do with the returned Twig Environment in order to render a template with my custom template loader attached?
Answers.UserDisplayName: lowe_22
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-01T04:58:45.487Z
Answers.Text: @brad-bell this doesn't look possible in Craft3?
Answers.UserDisplayName: Leevi Graham
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-09-02T02:48:07.817Z
Answers.LastActivityDate: 2016-09-02T02:48:07.817Z
Answers.UserDisplayName: Brad Bell
Body: <p>Twig lets you provide alternate (or multiple) template loaders. I'd like to take advantage of this to do use a bespoke loader to pull in components from a pattern library using a shorthand syntax like <code>{% include '*mycomponent' %}</code> or similar.</p>
  
  <p>Does Craft expose the environment used for loading templates in a way that I can append/overwrite the default filesystem loader with my own custom implementation?</p>
  
  <p>Any pointers in the right direction would be much appreciated!</p>
  
Tags: <templating><twigextension>
Title: Is is possible to add a bespoke Twig template loader?
ThreadText: # Is is possible to add a bespoke Twig template loader?
  
  (Asked by: username_0 on 2016-09-01)
  
  Twig lets you provide alternate (or multiple) template loaders. I'd like to take advantage of this to do use a bespoke loader to pull in components from a pattern library using a shorthand syntax like `{% include '*mycomponent' %}` or similar.
  
  Does Craft expose the environment used for loading templates in a way that I can append/overwrite the default filesystem loader with my own custom implementation?
  
  Any pointers in the right direction would be much appreciated!
  
  **Tags:** templating, twigextension
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-09-02. Score: 0 | Accepted answer
  
  When you call Craft's [`TemplatesService->getTwig()`](https://craftcms.com/classreference/services/TemplatesService#getTwig-detail) (`craft()->templates->getTwig()`), the first parameter you can pass in is your custom template loader classname.
  
  i.e. `craft()->templates->getTwig('\My\Awesome\Plugin\TemplateLoader, array('my' => 'options')`
  
  > **Comments:**
  > **username_0**: Many thanks @username_1 that is exactly what I was looking for! Top stuff.  
  > **username_2**: I'm trying to do the same thing as Mark, but am struggling to see how this fits into the plugin architecture. What do I need to do with the returned Twig Environment in order to render a template with my custom template loader attached?  
  > **username_3**: @username_1 this doesn't look possible in Craft3?  
  
  ---
  
  