-1

I have a Symfony Form and I try to display a SelectField with different Icons.

My ChoiceType looks like this

  ->add('icon', ChoiceType::class, [
            'choices'  => [
                '' => '',
                '' => '',
            ],
            'mapped' => false,
        ])

My CSS looks like this

select { font-family: 'FontAwesome', Verdana }

When I render a normal select div it works very well and i can see the icons.

But when try it via the Symfony Form it does not work. I have already read other Threads with the same problem. One solution was the to set the auto-escape of twig to false and try to work with the raw tag. But still i just see the pure text "" and not the Icons in the Select Box.

LittleEast
  • 19
  • 7

1 Answers1

0

One option, you can do this using the html_entity_decode function

public function buildForm(FormBuilderInterface $builder, array $options)
{
    // prepare an array with icons
    $icons =  [
        '',
        '',
    ];
    
    // decode our icons
    $icons = array_flip(array_map('html_entity_decode',$icons));
    
    // add field to formBuilder
    $builder->add('icon', ChoiceType::class, [
        'choices'  => $icons,
        'mapped' => false,
    ]);

}

add css

select { font-family: 'FontAwesome'}
emrdev
  • 2,155
  • 3
  • 9
  • 15
  • Thank you very much! This works perfectly! Now i have a second problem. I want also render the labels of my chartJs Chart as Icons. So i set the label to an array filled with .... I set the Font of the Chart and the Label to my Iconfont But still when i render the Chart i just see the hardcoded  as labels and not the Icons. You maybe have any suggestion? Kind regards, Magnus – LittleEast Mar 16 '22 at 13:15