Search code examples
symfonysymfony-forms

Can you create something like "pre-labels" in a Symfony Form?


Is there a way to make something like Pre-Label in a Symfony Form? I want to format it differently than the normal label. I already tried it with HTML-injection in the normal label-option, like this:

$form->add('answer', TextAreaType::class, [
     'label' => '<span>'.$data->category.'</span>'.$data->description
 ]);

But this doesn't work. Does someone else has an idea?


Solution

  • I found something like a workaround:

    {% for question in question %}
        <h1>{{ question.vars["value"].question.category.name }}</h1>
        {{ question.vars["value"].question.description }}
        {{ form_errors(question) }}
        {{ form_widget(question, { 'attr': { 'class': 'form-control' }}) }}
    {% endfor %}