Search code examples
neoscmstyposcript2

How to define and access local variable in Typoscript 2 (Neos)?


I have created a custom NodeType "Events" with a custom TS2 file in Neos, but I guess it is more a general question about Typoscript 2.

prototype(Some.Namespace:Events) < prototype(TYPO3.Neos:Document) {
    ...

    sortOrder = ${request.arguments.sortOrder  == 'asc' ? 'asc' : 'desc'}
    otherVariable = ${sortOrder}

    ...
}

Of course this is simplified to focus on the issue:

I want to assign the value of the variable sortOrder (which is "asc" or "desc") to another variable named otherVariable.

How can I do that? I cannot access the value using ${sortOrder}, which returns always NULL.


Solution

  • All you need to do is add this as below and {otherVariable} in your fluid template will work. Flush cache in case you sill have NULL.

    sortOrder = ${request.arguments.sortOrder  == 'asc' ? 'asc' : 'desc'}
    otherVariable = ${this.sortOrder}