<p>Perhaps instead of trying to get a template name, use the entry type as the template name, similar to the method that you linked to. In the link, it doesn't check which template is assigned to an entry, but instead, uses the entry type to load a template with the same name. In your example that might look like this:</p>

<pre><code>craft()-&gt;templates-&gt;render('path/to/template/' . $entry.type, [
  'entry' =&gt; $entry
])
</code></pre>

<p>Where your template would be named the same as the handle for your entry type. Does that make sense?</p>

CC BY-SA 3.0
2016-02-29T19:37:12.403Z
2016-02-29T19:37:12.403Z
Ben Wilkins
<p>I'm using many "entry type" templates as described here: <a href="http://buildwithcraft.com/help/entry-type-templates" rel="nofollow">http://buildwithcraft.com/help/entry-type-templates</a>. I'm using ElementAPI to render full entries as HTML embedded into JSON. I'm using this transformer method:</p>

<pre><code>craft()-&gt;templates-&gt;render('path/to/template/template-name', [
    'entry' =&gt; $template
])`
</code></pre>

<p>This works fine. But I need to assign the corresponding template to each entry-type. I have not found a solution. I can't seem to access the name or path of the assigned template. I don't really need the path, but need the name. The following seems right, but doesn't work:</p>

<p><code>'path/to/template/' . $template-&gt;getTemplateName()</code></p>

<p>Any ideas??</p>

<p>Thanks!</p>

CC BY-SA 3.0
2016-01-05T20:49:23.870Z
What type of object is `$template`?  `getTemplateName()` won't work unless it's an actual `\Twig_Template` class.
Brad Bell
<plugin-elementapi><error-templates>
ElementAPI -> Find entry template name
# ElementAPI -> Find entry template name

(Asked by: username_0 on 2015-11-25)

I'm using many "entry type" templates as described here: http://buildwithcraft.com/help/entry-type-templates. I'm using ElementAPI to render full entries as HTML embedded into JSON. I'm using this transformer method:
craft()->templates->render('path/to/template/template-name', [
    'entry' => $template
])`

This works fine. But I need to assign the corresponding template to each entry-type. I have not found a solution. I can't seem to access the name or path of the assigned template. I don't really need the path, but need the name. The following seems right, but doesn't work:
'path/to/template/' . $template->getTemplateName()
Any ideas??
Thanks!

**Tags:** plugin-elementapi, error-templates
> **Comments:**
> **username_1**: What type of object is `$template`?  `getTemplateName()` won't work unless it's an actual `\Twig_Template` class.  

---

## 1 answers

### Answer by username_2 on 2016-02-29. Score: 2

Perhaps instead of trying to get a template name, use the entry type as the template name, similar to the method that you linked to. In the link, it doesn't check which template is assigned to an entry, but instead, uses the entry type to load a template with the same name. In your example that might look like this:
craft()->templates->render('path/to/template/' . $entry.type, [
  'entry' => $entry
])

Where your template would be named the same as the handle for your entry type. Does that make sense?


---

