简体   繁体   English

Symfony自定义表单字段类型块未呈现

[英]Symfony Custom Form Field Type Block not rendering

Trying to build out a custom form field type in Symfony, but the widget block is not rendering. 尝试在Symfony中构建自定义表单字段类型,但未渲染小部件块。 I set up a widget for a text field type in the same file, and that rendered properly. 我在同一文件中为文本字段类型设置了一个小部件,并且该小部件已正确显示。 What would cause my widget to not find it's template block? 是什么导致我的小部件找不到模板块?

MediaGalleryType.php MediaGalleryType.php

class MediaGalleryType extends AbstractType
{
    public function getParent()
    {
        return TextType::class;
    }
}

mediagallery.html.twig mediagallery.html.twig

{% block mediagallery_widget %}
    HTML Goes here
{% endblock %}
{% block text_widget %}
    This replaces all text type fields
{% endblock %}

twig.yaml twig.yaml

twig:
    form_themes:
        - 'mediagallery.html.twig'

After some more digging around in sourcecode for Symfony form types, I found a method I can extend that returns the block prefix. 在针对Symfony表单类型的源代码中进行了更多挖掘之后,我发现了可以扩展的方法,该方法返回块前缀。

public function getBlockPrefix()
{
    return 'mediagallery';
}

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

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