Twig: 2.11 error - Template cannot be used as a trait

Created on 4 Jun 2019  路  11Comments  路  Source: twigphp/Twig

After upgrading to twig 2.11.1 (from 2.10.x) the code below throws an error, in previous versions it worked fine.

{% block datetime_widget %}
    {% use 'form_div_layout.html.twig' with datetime_widget as base_datetime_widget %}    
    <div class="form-group date-time-group">
        {{ block('base_datetime_widget') }}
    </div>
{% endblock %}

The error:

Template "form_div_layout.html.twig" cannot be used as a trait.

Most helpful comment

2.11.2 with the fix released

All 11 comments

Can you create a template that reproduce this issue (via https://twigfiddle.com/ if possible)?

FYI I am getting this too after upgrading, this is coming from the symfony 4.2.9 bootstrap_4 form theme template (globally), specifically the base one causes the error. Downgrading to 2.10.0 fixes the issue. Working on making a reproducible example that I can make public.

@fabpot one thing I did notice is if I load via a request to my application with no cache, it works fine and the isTraitable is true, but if going from CC it is showing as false.

Will report back when I have a way to reproduce, but most likely won't have time to look until later this week.

I had the issue on one of my projects and upgrading to v2.11.1 and removing the cache did work.

@fabpot manually removing the cache does indeed seem to work, strange that a cache-clear after composer update didn't resolve this issue

@fabpot It seems that manually removing the cache or a cache:clear --no-warmup doens't trigger this error but a regular cache:clear will trigger it.

3051 should fix the problem. @acrobat Can you confirm?

@fabpot #3054 seems to fix the issue! The exception is not throw after a regular cache:clear. Thanks!

confirmed fixes here too.

2.11.2 with the fix released

same error. How to fix this error?

@lchhieu Updating twig to atleast 2.11.2 should fix this issue.

Was this page helpful?
0 / 5 - 0 ratings