How to assign variable in fluid?

Vishal Tanna picture Vishal Tanna · Jun 12, 2015 · Viewed 18.9k times · Source

I want viewhelper that can be helpful to assign variable in fluid, I dont want variable to be passed from controller.

Answer

Mihir Bhatt picture Mihir Bhatt · Jun 15, 2015

Install extension called vhs from TYPO3 repository

Define namespace like following at the top of your fluid template

{namespace v=FluidTYPO3\Vhs\ViewHelpers}

Then use set viewhelper

<v:variable.set name="test" value="12345" />
Value of test : {test}

{test} will return value 12345

For registering global variable

<v:variable.register.set name="test" value="12345"/>]

Get value of global variable

Value of global variable : <v:variable.register.get name="test">

Since TYPO3 8.7, fluid introduces viewhelper for the variable (No need of VHS)

<f:variable name="myvariable">My variable's content</f:variable>
<f:variable name="myvariable" value="My variable's content"/>

With inline style usage

{f:variable(name: 'myvariable', value: 'My variable\'s content')}
{myoriginalvariable -> f:variable.set(name: 'mynewvariable')}