How can I set the template which is rendered with a custom form field type?
I'm actually developping a custom form field type which extends a file
form field type. The documentation about that has not been written yet.
I have created my custom field & register it like service.
Custom form field type:
class CustomFileType extends AbstractType
{
public function getParent(array $options)
{
return 'file';
}
public function getName()
{
return 'custom_file';
}
}
Service:
<service id="form.type.custom_file" class="Namespace\CustomFileType">
<tag name="form.type" alias="custom_file" />
</service>
开发者_JAVA百科
I can use it like a file field but I don't know how can I set the template which will be render with my custom field.
In the template rendering the form, you can include this:
{% form_theme form _self %}
{% block custom_file_widget %}
{# rendering of the widget goes here #}
{% endblock %}
Check how the form_div_layout.html.twig file is made and you'll understand the underlying mechanism.
精彩评论