Answers.Body: <p>In Craft 3, <code>{{ _self.getTemplateName() }}</code> throws an error, but <code>{{ _self }}</code> does the trick.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-09-05T11:34:30.720Z
Answers.LastActivityDate: 2018-09-05T11:34:30.720Z
Answers.UserDisplayName: hashchange
Answers.Body: <p>Post marked as answer doesn't work for me nowadays.
  For me works:</p>
  <pre><code>{{ craft.app.requestedParams.template }}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-11-25T10:10:48.623Z
Answers.Text: Thanks, works for me too (Craft 4).
Answers.UserDisplayName: GazCrane
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-05-26T18:54:30.833Z
Answers.Text: Thanks, works in CraftCMS 5 as well.
Answers.UserDisplayName: Martin Ille
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-06-17T21:39:23.133Z
Answers.LastActivityDate: 2022-06-17T21:39:23.133Z
Answers.UserDisplayName: Дмитрий Боровков
Answers.Body: <p>I don't believe this is currently possible outside of the context of a Craft plugin.  Inside of a plugin, you could probably do it through a Twig extension so that you have access to the template instance, where you could call $template->getTemplateName(), which is part of Twig's Twig_Template abstract class.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-25T05:57:47.347Z
Answers.Text: Thanks Brad, would you consider adding a tag for it a some point?
Answers.UserDisplayName: Gareth
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-25T07:43:45.420Z
Answers.Text: I don't see why not!
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-24T21:34:42.800Z
Answers.LastActivityDate: 2014-06-24T21:34:42.800Z
Answers.UserDisplayName: Brad Bell
Answers.Body: <p>This applies to Craft 2. For Craft 3+, see <a href="https://craftcms.stackexchange.com/a/27606/4748">hashchange's answer</a>.</p>
  <hr />
  <p>You can get the current template’s name like so:</p>
  <pre><code>{{ _self.getTemplateName() }}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-04-21T15:09:06.313Z
Answers.Text: Careful with this; it returns an object of type `Twig_Markup`, which is then casted to a string. If you need template name strictly as a string, use `_self.getTemplateName().__toString`
Answers.UserDisplayName: Alex
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2014-07-07T21:35:28.417Z
Answers.LastActivityDate: 2022-12-16T02:26:12.473Z
Answers.LastEditDate: 2022-12-16T02:26:12.473Z
Answers.UserDisplayName: Brandon Kelly
Body: <p>Is it possible to output the template name being used? Using a global variable or something similar? I am wanting to check which template is being used in a conditional.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-06-24T21:32:54.933Z
Comments.Text: I don't think that's possible, but can you give an example why you want to check the template-name?
Comments.UserDisplayName: Victor
Tags: <templating><variable>
Title: How can I make a template output its own filename?
ThreadText: # How can I make a template output its own filename?
  
  (Asked by: username_0 on 2014-06-24)
  
  Is it possible to output the template name being used? Using a global variable or something similar? I am wanting to check which template is being used in a conditional.
  
  **Tags:** templating, variable
  
  > **Comments:**
  > **username_1**: I don't think that's possible, but can you give an example why you want to check the template-name?  
  
  ---
  
  ## 4 answers
  
  ### Answer by username_7 on 2014-07-07. Score: 15 | Accepted answer
  
  This applies to Craft 2. For Craft 3+, see [username_2's answer](https://craftcms.stackexchange.com/a/27606/4748).
  
  ---
  
  You can get the current template’s name like so:
  
  ```
  {{ _self.getTemplateName() }}
  
  ```
  
  > **Comments:**
  > **username_8**: Careful with this; it returns an object of type `Twig_Markup`, which is then casted to a string. If you need template name strictly as a string, use `_self.getTemplateName().__toString`  
  
  ---
  
  ### Answer by username_2 on 2018-09-05. Score: 10
  
  In Craft 3, `{{ _self.getTemplateName() }}` throws an error, but `{{ _self }}` does the trick.
  
  
  ---
  
  ### Answer by username_3 on 2022-06-17. Score: 6
  
  Post marked as answer doesn't work for me nowadays.
  For me works:
  
  ```
  {{ craft.app.requestedParams.template }}
  
  ```
  
  > **Comments:**
  > **username_4**: Thanks, works for me too (Craft 4).  
  > **username_5**: Thanks, works in CraftCMS 5 as well.  
  
  ---
  
  ### Answer by username_6 on 2014-06-24. Score: 5
  
  I don't believe this is currently possible outside of the context of a Craft plugin. Inside of a plugin, you could probably do it through a Twig extension so that you have access to the template instance, where you could call $template->getTemplateName(), which is part of Twig's Twig\_Template abstract class.
  
  > **Comments:**
  > **username_0**: Thanks username_6, would you consider adding a tag for it a some point?  
  > **username_6**: I don't see why not!  
  
  ---
  
  