Symfony 4 EasyAdmin - Property does not render when overriding bundle template

1.8k Views Asked by At

Using Symfony 4.1 with EasyAdmin bundle.

I am trying to override a template for the User (one of my entites) show view. I have set up the override and it is working.

  1. Created a user_show.html.twig and registered it in the easy_admin config file.

  2. I then copy the twig blocks from corresponding bundle template for show.html.twig.

  3. Then tried to render a User property from my user entity, called profile height.

Here are twig blocks I'm overriding:

{# templates/admin/user_show.html.twig #}
{% extends '@EasyAdmin/default/show.html.twig' %}

{% block content_title %}
    Test Title {{ dump() }}
{% endblock %}

{% block main %}
    {{ profileHeight }}
{% endblock %}

Error

Twig_Error_Runtime: Variable "profileHeight" does not exist

Debug

I did a dump and found the property is present on page:

enter image description here

Why can twig not see these variables appearing in the dump? How can I render the properties I want in the template?

1

There are 1 best solutions below

0
Zorpen On BEST ANSWER

As you can see in your dumped data, there is entity array key which hold the User object. So instead of:

{% block main %}
  {{ profileHeight }}
{% endblock %}

Use:

{% block main %}
  {{ entity.profileHeight }}
{% endblock %}