Quantcast
Channel: Active questions tagged symfony4 - Stack Overflow
Viewing all articles
Browse latest Browse all 3925

Pass custom data to Form Theme in Symfony/Twig

$
0
0

I'm new to Symfony, currently working with 4.4, and am trying to implement a simple form theme for one specific form, i.e. the theme is in the same file as the form's html.twig file. I have my own form_row block and I'm trying to pass in custom data (an icon to use within the div) when calling it, so something like (this is highly summarised!):

{{ form_row(signUpForm.email, {    attr: { placeholder: 'e.g. bobsmith@gmail.com' },    icon: 'envelope'}) }}

then try to render in the form as

{%- block form_row -%}<div>    {{ form_label(form) }}    {{ form_widget(form, {attr: class: 'input'}) }}<i class="icon {{ icon }}"></i></div>

I tried also passing icon via the formBuilder, along the lines of

$builder    ->add('email', EmailType::class, ['attr'=> ['icon' => 'envelope']])

but no joy. Surely this must be possible! Any assistance would be much appreciated. Thanks


Viewing all articles
Browse latest Browse all 3925

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>