Michael Mauracher
Michael Mauracher

Reputation: 201

TYPO3 - Pass a variable from Fluid to a cObject

I'm using fluidcontent and I would like to render a plugin in a content-element. Therefore I created the following COA:

form = COA
form {
     15 < tt_content.list.20.extname_form
     15.settings.id = |
}

This object is getting rendered in the fluid template with the cOject viewhelper.

<f:cObject typoscriptObjectPath="form" data="testId" />

The rendering process works fine.

The problem is that I can't access the data variable inside the COA object. In the form template the content of the variable settings.id is | and not testId.

I tried to render the plugin with the vhs viewhelper request.render, but also there I have the problem passing variables.

<v:render.request action="request" controller="Form" extensionName="ExtName" pluginName="Form" vendorName="VendorName" arguments="{_all}" />

Upvotes: 3

Views: 3676

Answers (3)

webman
webman

Reputation: 1203

just some help (maybe) in your fluid template you can use :

<f:debug>{_all}</f:debug>

so you can check the lot of information available, otherwise in your controller:

\TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($yourVariable);

Upvotes: 1

Claus Due
Claus Due

Reputation: 4261

There is another way using a global registry for variables. TYPO3 contains a so-called "LOAD REGISTER" which means a static storage for variables. The VHS extension contains ViewHelpers to interact with that storage:

https://fluidtypo3.org/viewhelpers/vhs/master/Variable/Register/GetViewHelper.html

Using the set variant you can add your variable, then call f:cObject and regardless of how deep inside the rendering stack your next fluid template sits, using the get variant retrieves the value.

Very useful if for example you use content elements with other nested content elements, e.g. retrieve or re-define the value at any nesting depth.

NB: also accessible in TypoScript as well as custom PHP executed through TYPO3, by using https://docs.typo3.org/typo3cms/TyposcriptReference/ContentObjects/LoadRegister/Index.html. So overall it may be much, much simpler to handle and definitely more flexible than strict passing of arguments.

Upvotes: 4

Ren&#233; Pflamm
Ren&#233; Pflamm

Reputation: 3354

If you define a String as data use the .current = 1 option of stdWrap:

form = COA
form {
     15 < tt_content.list.20.extname_form
     15.settings.id.current = 1
}

But your "extname_form" should use the stdWrap on the settings else you should use "variables":

form = COA
form {
     15 < tt_content.list.20.extname_form
     15.variables.id = TEXT
     15.variables.id.current = 1
}

Example for use of stdWrap for settings:

form = COA
form {
     15 < tt_content.list.20.extname_form
     15.settings.id.current = 1
}

In your controller action:

  /** @var \TYPO3\CMS\Extbase\Service\TypoScriptService $typoScriptService */
  $typoScriptService = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Service\TypoScriptService::class);
  $typoScriptSettings = $typoScriptService->convertTypoScriptArrayToPlainArray($this->settings);
  $this->settings['id'] = $this->configurationManager->getContentObject()->stdWrap($typoScriptSettings['id'], $typoScriptSettings['id.']);

Now your settings.id is parsed by stdWrap and should contain your cObjectViewHelper Data.

Upvotes: 0

Related Questions