Peter Wajcowicz's avatar

Dynamic component name

Hi,

Is there a way to display component in blade file using variable name?

Im trying to do something like this:

<x-{{ $component_name }} />

but that doesn't seems to work.

0 likes
5 replies
Snapey's avatar

those <x- tags don't really exist. The blade compiler turns them into regular html snippets. So to do what you are asking, I think you would need a blade pre-compiler that took your view file and converted it to blade file.

Happy to be corrected by others

Peter Wajcowicz's avatar

I see. It would be really grat to have something like vuejs has.

<x-component is="component-name" />
Peter Wajcowicz's avatar

Thanks for the suggestrion @snapey. I created inline component where i precompile the string and then compile it again ;)


$precompiled = resolve('blade.compiler')->compileString('<div>
            <x-' . $this->is . ' />
        </div>');

        return resolve('blade.compiler')->compileString($precompiled);

Please or to participate in this conversation.