philipp
philipp

Reputation: 16495

assign custom function call to variable

I am quite new to Typo3 and Fluid, but I guess what I am after is quite basic.

As an Analogy: Twig can extended, so it is possible to create a custom function which can be used like that:

{% set id = uid() %}
<input id="{{ id }}" … /><label for="{{ id }}">…</label>

Is such a thing possible with Fluid? Do I need to install other extensions, or can that be done with basic fluid extension?

Upvotes: 0

Views: 223

Answers (1)

Mathias Brodala
Mathias Brodala

Reputation: 6460

In Fluid you have two ways to achieve this:

  1. Prepare the desired data in the controller and assign it to the view as variable.
  2. Create a custom viewhelper which contains the logic to build the desired data.

You can also combine these two and store the result of a viewhelper call in a variable using the f:variable viewhelper (more usage examples):

<f:variable name="myvariable">{acme:custom.viewhelper()}</f:variable>

In this specific case you can also install the VHS extension, the swiss army knife of Fluid, and use its UniqIdViewHelper Notice that you normally don't need this for forms since you bind them to (domain) objects you want to create/edit and let Extbase/Fluid handle the rest.

Upvotes: 1

Related Questions