1

Trying to build out a custom form field type in Symfony, but the widget block is not rendering. 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

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

mediagallery.html.twig

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

twig.yaml

twig:
    form_themes:
        - 'mediagallery.html.twig'
1
  • If you're not using autoconfigure, make sure to tag your service with form.type. Commented Oct 12, 2018 at 10:04

1 Answer 1

1

After some more digging around in sourcecode for Symfony form types, I found a method I can extend that returns the block prefix.

public function getBlockPrefix()
{
    return 'mediagallery';
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.