Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

{% nocache %} seems incompatible with {% embed %} #22

Open
nstCactus opened this issue Dec 9, 2020 · 2 comments
Open

{% nocache %} seems incompatible with {% embed %} #22

nstCactus opened this issue Dec 9, 2020 · 2 comments

Comments

@nstCactus
Copy link

Description

Using the {% nocache %} around an {% embed %} tag throws a yii\base\ErrorException:

Cannot declare class __TwigTemplate_58ca26ca050e28ccd1000e621e244e86d4395a3d535ac28fb668ef8f85a11918, because the name is already in use

Steps to reproduce

To reproduce, create the following templates and navigate to /nocache.

templates/nocache/index.twig:

{% nocache %}
    {% embed 'nocache/_list.twig' with { heading: 'Drinks' } %}
        {% block listItems %}
            {% include 'nocache/_item.twig' with { name: 'Beer' } %}
            {% include 'nocache/_item.twig' with { name: 'Orange juice' } %}
            {% include 'nocache/_item.twig' with { name: 'Water' } %}
        {% endblock %}
    {% endembed %}
{% endnocache %}

_templates/nocache/list.twig:

<h1>{{ heading }}</h1>
<ul>
    {% block listItems %}{% endblock %}
</ul>

_templates/nocache/item.twig:

<li>{{ name }}</li>

Additional information

  • No-Cache version: 2.0.6
  • Craft CMS version: 3.5.16
  • PHP version: 7.4
@ttempleton
Copy link
Owner

Thanks for reporting this, @nstCactus. For some reason, it's ending up with two compiled templates being created for index.twig, causing this error. I'm not really sure why that's happening at this stage, but as a workaround, see if you can localise your usage of {% nocache %} to the specific places within the {% embed %} block or the embedded/included templates that need it.

@rungta
Copy link

rungta commented Jan 20, 2021

I just ran into the same issue — tried using {% nocache %} with the {% embed %} tag and it complains about a template class collision.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants