如何在流体中分配变量?

Vis*_*nna 1 typo3 fluid view-helpers

我想viewhelper可以帮助分配流量变量,我不希望变量从控制器传递.

Mih*_*att 12

从TYPO3存储库安装名为vhs的扩展

在流体模板的顶部定义名称空间,如下所示

{namespace v=FluidTYPO3\Vhs\ViewHelpers}
Run Code Online (Sandbox Code Playgroud)

然后使用set viewhelper

<v:variable.set name="test" value="12345" />
Value of test : {test}
Run Code Online (Sandbox Code Playgroud)

{test}将返回值12345

用于注册全局变量

<v:variable.register.set name="test" value="12345"/>]
Run Code Online (Sandbox Code Playgroud)

获取全局变量的值

Value of global variable : <v:variable.register.get name="test">
Run Code Online (Sandbox Code Playgroud)

从TYPO3 8.7开始,流体为变量引入了viewhelper(不需要VHS)

<f:variable name="myvariable">My variable's content</f:variable>
<f:variable name="myvariable" value="My variable's content"/>
Run Code Online (Sandbox Code Playgroud)

使用内联样式

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


Sve*_*ven 8

从TYPO3 8.6开始,这可能没有扩展名"vhs":

<f:variable name="myvariable" value="My variable's content"/>
Run Code Online (Sandbox Code Playgroud)

请参阅https://docs.typo3.org/typo3cms/extensions/core/Changelog/8.6/Feature-79402-VariableViewHelperForFluid.html