Nova Icon Select

Viewed 288

I would like to integrate a list of icons in a drop-down list of a back office (laravel nova), I found something to help me on this link https://novapackages.com/packages/bernhardh/nova-icon-select

I followed all the procedure, but I block at the level of the display of my icons, I currently have this code in my models:

    public static function getIconsOptions(): array
    {
        NovaIconSelect::make("Icon")
        ->setIconProvider(IconProvider::make()->setOptions([
            [
                'label' => 'aaaa',
                'value' => '<i class="fa-brands fa-apple-pay"></i>',
            ],
            [
                'label' => 'aaaa',
                'value' => 'my-icons-2',
            ],
            [
                'label' => 'aaaa',
                'value' => 'my-icons-3',
            ],
        ]));
        $options = [];
        foreach(self::ICON_NAMES as $key => $icon)
            $options[$key] = trans('appearance.'.$icon);

        return $options;
    }

and this code in my blade

<select class="js-visual-field w-full form-control form-input form-input-bordered" data-field-name="icon_select_{{ $i }}">
    <option value="">{{ trans('nova-visual-composer::templates.'.$templateName.'.no_icon') }}</option>
    @foreach(\App\Models\Appearance::getIconsOptions() as $key => $txt)
        <option value="{{ $key }}">{{ $txt }}</option>
    @endforeach
</select>
1 Answers

To render HTML in blade, you need to use {!! $txt !!} instead of {{ $txt }}. Otherwise, the string will be auto escaped. So:

<select class="js-visual-field w-full form-control form-input form-input-bordered" data-field-name="icon_select_{{ $i }}">
    <option value="">{{ trans('nova-visual-composer::templates.'.$templateName.'.no_icon') }}</option>
    @foreach(\App\Models\Appearance::getIconsOptions() as $key => $txt)
        <option value="{{ $key }}">{!! $txt !!}</option>
    @endforeach
</select>
Related