简体   繁体   English

Symfony 4 EasyAdmin - 覆盖包模板时不呈现属性

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

Using Symfony 4.1 with EasyAdmin bundle.使用 Symfony 4.1 和 EasyAdmin 包。

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.创建了一个 user_show.html.twig 并将其注册到 easy_admin 配置文件中。

  2. I then copy the twig blocks from corresponding bundle template for show.html.twig.然后我从 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:我做了一个转储,发现该属性出现在页面上:

在此处输入图片说明

Why can twig not see these variables appearing in the dump?为什么 twig 看不到这些变量出现在转储中? How can I render the properties I want in the template?如何在模板中呈现我想要的属性?

As you can see in your dumped data, there is entity array key which hold the User object.正如您在转储的数据中所见, entity数组键包含User对象。 So instead of:所以而不是:

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

Use:用:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM