Can't use normal template includes after using commentsInclude()
danbrellis opened this issue · comments
Describe the bug
In a twig template, once the commentsIncludes() function is run, the template path is changed, so trying to include another template afterwards will give a "Unable to find the template" error.
Steps to reproduce
{# blog/_entry.twig #}
{% for comment in commentsQuery.all() %}
{{ commentsInclude('_includes/comment') }}
{% endfor %}
{{ include('_partials/authorCard') }}
In this situation the authorCard template fails to load. If you follow the trace, in _resolveTemplateInternal()
located in /vendor/craftcms/cms/src/web/View.php on line 860 it calls $this->_templatesPath
. After using commentsInclude()
, the template path is set to the comments plugin template directory.
Craft CMS version
3.7.47
Plugin version
1.9.3
Multi-site?
No
Additional context
The workaround to fix this is to reset the template path following commentsInclude()
before calling any other includes:
{# blog/_entry.twig #}
{% for comment in commentsQuery.all() %}
{{ commentsInclude('_includes/comment') }}
{% endfor %}
{% do view.setTemplatesPath(alias("@templates")) %} {# reset template path #}
{{ include('_partials/authorCard') }}
Ideally, however, the commentsInclude
php function (in vendor/comments/src/twigextensions/Extension.php) resets it for us.
Should be fixed for the next release. To get this early, change your verbb/comments
requirement in composer.json
to:
"require": {
"verbb/comments": "dev-craft-3 as 1.9.3",
"...": "..."
}
Then run composer update
.
Fixed in 1.9.4