Edge: Dynamic path in component


#1

Hi!

I cant manage to get a component with dynamic path.

@each((block, id) in blockData)
        
            @!component('admin/modules/content-block/blocks/' + block.type, {
                id: 'old-' + id,
                block: block
            })
        @endeach

Is this possible somehow? Works in blade, twig etc.

Thx in advance!


#2

How about doing it with a global function?

View.global('componentFor', function (type) {
  return `admin/modules/content-block/blocks/${type}`
})

and then it as

@!component(componentFor(block.type))

#3

I’ll try that! Thx!


#4

It doesn’t seem to work. I get runtimeException when i use variables or functions as params in component. Did you get it to work?

E_CANNOT_PARSE: RuntimeException: E_CANNOT_PARSE: RuntimeException: E_CANNOT_PARSE: RuntimeException: E_CANNOT_PARSE: Error: Cannot parse ThisExpression expression Report to the package author Report to the package author Report to the package author Report to the package author