In my edit.html.twig I have:
{% form_theme edit_form 'MyBundle:Entity:form.html.twig' %}
{% set img_src = asset('120x100.jpg') %}
{{ dump(img_src) }}
{{ dump(entity) }}
{{ form_widget(edit_form, {'form_type': 'horizontal', 'img_src': img_src }) }}
There I have img_src and entity dumped with no problem.
In form.html.twig I have:
{% extends 'MyBundle:Form:bootstrap.html.twig' %}
{% block _entity_field_widget %}
{{ dump(img_src) }}
{{ dump(entity) }}
{% set type = 'hidden' %}
{{ block('form_widget_simple') }}
{% endblock _channel_media_widget %}
bootstrap.html.twig is just a bootstraped *form_div_layout.html.twig*
And in that widget I have no img_src nor entity.
Any ideas how to get entity in widget? Should it be passed to form widget or is there another way? What am I doing wrong?
Each symfony form type extents AbstractType class.
AbstactType class has method:
public function buildView(FormView $view, FormInterface $form, array $options)
{
$view->set('img_src', '120x100.jpg');
$view->set('my_variable', $foo);
}
You can create this method on your form type and next in your twig:
{{ asset(img_src) }}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With