How to get name of template that was chosen for request? For convenience it would be rather useful if there was a way for me to achieve the following inside my main layout template:

&lt;body class="template--{{ getNameOfPageTemplateHere|replace({ '/':'-', '_':'' }) }}"&gt;


Such that a page rendered using the template "blog/_entry" would have the following body tag:

&lt;body class="template--blog-entry"&gt;


Is this possible?
Maybe not the solution you was looking for, but here is an alternative solution I'm using.

Put a Twig block in your "master template" (_layout.html?) like this:

&lt;body class="{% block bodyClass %}{% endblock bodyClass %}"&gt;


And from my templates I can add classes to the body tag like this:

{% block bodyClass %}{{ parent() }} news-index anotherclass{% endblock bodyClass %}


Or replace the classes by omitting the parent() like this:

{% block bodyClass %}news-index anotherclass{% endblock bodyClass %}