[SOLVED] Fusion variables

Hello,

this should be an easy question. I am trying to find a way to access variables out of the current { block } in fusion, but I don’t know where to look to find the right syntax. As an example, in the following code block :

// This is the default page configuration
prototype(Vendor.Site:Page) < prototype(Page) {
    templatePath = 'resource://Vendor.Site/Private/Templates/Page/Default.html'

    head {
        stylesheets.site = Neos.Fusion:Template {
            templatePath = // I want the templatePath from above declaration here
            sectionName = 'stylesheets'
        }

        javascripts.site = Neos.Fusion:Template {
            templatePath = // Also here
            sectionName = 'headScripts'
        }
    }
}

So, I have multiple templatePath variables in that block and I want to declare their value only once and then grab it from that declaration when needed.

I found out that I can declare @context.templatePath and then get its value with ${templatePath}, but is this the best practice ? Also, where can I find some documentation and examples of usage about all these magic variables / functions ?

Thanks in advance !

Hey @dimitriadisg,

to access variables they need to be in the same context or declared via @context. So in your case you need to use @context to access them.

prototype(Vendor.Site:Page) < prototype(Page) {
    @context.templatePath = 'resource://.../Default.html'
    templatePath = ${templatePath}

    someOtherVar = 'abc'
    # same context, so variable can be accessed using "this"
    usingSomeOtherVar = ${this.someOtherVar + 'def'} 

    head {
        stylesheets.site = Neos.Fusion:Template {
            # other context so variable needs to be defined using @context
            # and can be accessed without "this" or any other prefix.
            templatePath = ${templatePath}
            sectionName = 'stylesheets'
        } 
    }
}

Hello @BenjaminK,

ah I see, so @context is the right way to do it, alright thanks !