Q: Silex 2.3 and custom form type should use custom template

52 Views Asked by At

My goal with Silex 2.3 and Symfony 4.2.0 is to write a custom form type. This form type should show an image and a text field (or choice, I do not know yet). Let's call it TextImageType.

So, I created a TextImageType:

<?php
  namespace App\Form\Type;

  use Symfony\Component\Form\AbstractType;
  use Symfony\Component\Form\Extension\Core\Type\TextType;

  use Symfony\Component\Form\FormBuilderInterface;
  use Symfony\Component\Form\FormInterface;
  use Symfony\Component\Form\FormView;
  use Symfony\Component\OptionsResolver\OptionsResolver;

  class TextImageType extends AbstractType {
  ....
  public function getBlockPrefix() {

      return 'textimage';
  }
}

Loading this class works; if I add bad code to the file, I'll get an error. Now, I tried to add a textimage-widget.html.twig with only that debug code:

{% block textimage_widget  %}
Hello world
<input type="text">
{% endblock %}

And I expected a 'widget', telling me "Hello world" and an input field. But the widget is not loaded from templates/form/textimage-widget.html.twig, so I need a simple working example how to add custom form types to the Silex system.

Thanks in advance!

1

There are 1 best solutions below

0
Sixtus On

Well, I found a solution: I added a form theme to templates/theme directory, containing a textimage_widget and load the theme by form_theme in my template file.