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

Template 'data.html.twig' does not have access context variables #569

Open
pamtbaau opened this issue May 23, 2022 · 2 comments
Open

Template 'data.html.twig' does not have access context variables #569

pamtbaau opened this issue May 23, 2022 · 2 comments
Assignees

Comments

@pamtbaau
Copy link

pamtbaau commented May 23, 2022

Since data.html.twig, has been refactored with commit c5902ed into a macro, the context variables like base_url are no longer accessible.

By design, Twig macros do not have access to the context.

When the form uses display and/or email actions, all variables are being passed to data.html.twig but since its refactoring into a macro, it does not have access to the context anymore.

This can be fixed as follows:

  • Pass the context into the macro, by altering the top and bottom line in data.html.twig as follows:
    {% macro render_field(form, fields, scope, context) %}
    {# Note: Use context to access available variables #}
    ...
    {{ macro.render_field(form, form.fields, '', _context) }}
    
  • Access the variables using context, like {{ context.base_url_absolute }}
@mahagr
Copy link
Member

mahagr commented May 23, 2022

Looks like it was your fix. Can you take a look?

@pamtbaau
Copy link
Author

A better solution could be to use PHP extract() to assign the content of context into local variables.

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