EasyAdmin3: Passing additional variables to twig-template (EDIT page)

Background

I want to display entity-independent information in the EDIT-page. According to the official documentation it can be solved with configureResponseParameters-function.

Problem

So I implemented that function into my CRUD-controller, but I am not not able to use/find that variable it in my twig template. Any idea? Thanks!

My Files

PersonCrudController.php

class PersonCrudController extends AbstractCrudController {
    public function configureCrud(Crud $crud): Crud {

        $crud->setFormThemes([
            'mystuff/person_edit_form.html.twig', '@EasyAdmin/crud/form_theme.html.twig'
        ]);

        return $crud;
    }

    public function configureFields(string $pageName): iterable {
        // ...
        yield TextField::new('specialDisplay')->setFormTypeOption('mapped', false);
        // ...
    }

    public function configureResponseParameters(KeyValueStore $responseParameters): KeyValueStore
    {
        $responseParameters->set('testtesttest', '123xyz');
        return $responseParameters;
    }
    // ...
}

mystuff/person_edit_form.html.twig

{% block _Person_specialDisplay_row %}
    {{ testtesttest }} {# throws: Variable "testtesttest" does not exist. #}
    {{ dump() }}       {# cannot find "testtesttest" anywhere in dump #}

    {# ... here comes the rest that is working perfectly ... #}
{% endblock %}

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *