symfony twig form theming

I have a Symfony Form for a file upload looking like

$builder
        ->add('imageFile', FileType::class, [
            'mapped' => false,
            'required' => false,
            'label' =>'user.edit.select_image',
            'constraints' => $coverConstraints
        ])
        ->getForm();

because of a bug in bootstrap 4 i have to theme it so it can show Select a file to upload in the box

     {% set tr = 'user.edit.select_image|trans' %}
      <div class="card-body">
                    {{ form_start(CoverForm) }}
                    {{ form_row(CoverForm.imageFile, {
                        attr: {
                            'placeholder': tr
                        }
                    }) }}
                    {{ form_errors(CoverForm) }}
                    {{ form_widget(CoverForm) }}
                    <button type="submit" class="btn btn-dark">{{ 'user.edit.form_submit'|trans }}</button>
                    {{ form_end(CoverForm) }}
      </div>

  <script>
        $('.custom-file-input').on('change', function(event) {
            var inputFile = event.currentTarget;
            $(inputFile).parent()
                .find('.custom-file-label')
                .html(inputFile.files[0].name);
        });
   </script>

My problem is that that variable tr doesn’t executed
Do you have any ideea how to aproach this ?

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *