doufenyu7610 2016-01-13 07:17
浏览 6
已采纳

如何覆盖奏鸣曲管理员中的显示字段

I want show the list of multiple attributes Name => value in a table overriding single field of only for PortsAdmin in ShowMapper

Ports Entity mapped with PortsAttributes Entity.

Relation of entity is OneToMany Ports with multiple attributes.

Admin View (Edit Action)

Edit View of attributes listing

Show Action

Show list of attributes

I want change attribute view same as edit Action.

  • 写回答

1条回答 默认 最新

  • duandaodao6951 2016-01-13 08:31
    关注

    You can create a custom template for the PostAttributes:

    Example:

    /* ShowMapper in admin */
    $showMapper->add('attributes', null, array(
        'template' => 'YOUR_TEMPLATE.html.twig' // <-- This is the trick
    ));
    

    In your template, you can extend the base show field (SonataAdminBundle:CRUD:base_show_field.html.twig), and override the field block. The variable named value stores the data in twig.

    Example:

    YOUR_TEMPLATE.html.twig

    {% extends 'SonataAdminBundle:CRUD:base_show_field.html.twig' %}
    
    {% block field %}
        {% for val in value %}
            {{ val.name }} - {{ val.value }} {# I'm just guessing the object properties #}
            <br/>
        {% endfor %}
    {% endblock %}
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题