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

Deprecated getAttributes() #250

Closed
garak opened this issue Nov 19, 2016 · 8 comments
Closed

Deprecated getAttributes() #250

garak opened this issue Nov 19, 2016 · 8 comments

Comments

@garak
Copy link
Collaborator

garak commented Nov 19, 2016

With last Twig version (1.28) I'm getting a deprecation warning:

Calling "getattributes" on template "knp_menu.html.twig" from template "foo.html.twig" is deprecated since version 1.28 and won't be supported anymore in 2.0.

this is the offending line in my foo.html.twig file:

{{ macros.attributes(attributes) }}
{# macros is from {%- import "knp_menu.html.twig" as macros -%} #}
@garak
Copy link
Collaborator Author

garak commented Nov 24, 2016

See symfony/symfony#20568

@stof
Copy link
Collaborator

stof commented Nov 24, 2016

The templates being in KnpMenu always import macros in places using them, so they should not trigger this deprecation.

This deprecation happens when you call a macro in a template while relying on an import statement done in the parent template instead of importing them in your template.
Please check your own templates which may be using our macro

@garak
Copy link
Collaborator Author

garak commented Nov 24, 2016

Sorry @stof I got lost. What is the proposed solution? Should I redefine the macro in my template or what else?

@stof
Copy link
Collaborator

stof commented Nov 24, 2016

no, you should not define the macro. you should import the macro (instead of relying on the implementation detail exposing you the macro imported by the parent template in some cases)

@garak
Copy link
Collaborator Author

garak commented Nov 24, 2016

Well, maybe I need to to give more details on my template. Here it is:

{% extends 'knp_menu.html.twig' %}
{% block item %}
    {% import "knp_menu.html.twig" as macros %}
    <li{{ macros.attributes(attributes) }}></li>
{% endblock %}

What should I do?

@garak
Copy link
Collaborator Author

garak commented Nov 25, 2016

Well, I resolved removing {% import "knp_menu.html.twig" as macros %} and re-defining the macro from knp_menu.html.twig in my template. It looks like a workaround, but at least it works.
If you can suggest a better solution, it would be much appreciated. Otherwise, feel free to close.
Thanks

@sgehrig
Copy link

sgehrig commented Nov 28, 2016

@garak I did experience the same issue. If you're using overwritten KNP menu templates it's highly possible that you overwrite more than one block. As the macros are being used in several blocks, you need to import the macros ({% import "knp_menu.html.twig" as macros %}) in every block they are being used. Formerly it did work without those imports because of the reasons @stof mentioned.

I'm overwriting the {% block item %} block as well as the {% block linkElement %} block and I had to add the macro import {% import "knp_menu.html.twig" as macros %} to both blocks to get rid of the deprecation message.

@wouterj
Copy link
Collaborator

wouterj commented Feb 5, 2017

Closing this issue is not in KnpMenu and the solution for people's template is nicely explained by @sgehrig

@wouterj wouterj closed this as completed Feb 5, 2017
hounded added a commit to hounded/AdminThemeBundle that referenced this issue Feb 15, 2017
dweichert added a commit to dweichert/moka that referenced this issue Mar 29, 2019
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

4 participants