user3852729
user3852729

Reputation: 45

TYPO3 DCE use curly bracket inside fluid template file

I have a DCE content element and now I need to add a json object inside this template with the text from the variables.

I tried many ways like

<f:format.raw>{</f:format.raw>

or

<f:format.alias map="{l: '{}', r: '}'}"> { json } </f:format.alias>

but nothing works.

<dce:format.WrapWithCurlyBraces>json</dce:format.WrapWithCurlyBraces>

was my last test but this generates an empty output. Is there any way to output some json with the variables from the dce inside?

<f:format.json>{"context": "https://schema.org/"}</f:format.json>

also tested, generates also an empty output.

DCE Version: 2.6.0
TYPO3: 9.5

Upvotes: 0

Views: 465

Answers (2)

Jonas Eberle
Jonas Eberle

Reputation: 2921

You don't need that many workarounds ;) You just used the JSON-ViewHelper incorrectly. It expects a (Fluid)-array as input.

<f:format.json value="{context: 'https://schema.org/'}" />

Since the " in the JSON will get escaped before being output to HTML we just use f:format:raw on the whole string.

<f:format.raw><f:format.json value="{context: 'https://schema.org/'}" /></f:format.raw>

Or, probably nicer:

<f:variable name="jsonData" value="{context: 'https://schema.org/'}" />
{jsonData -> f:format.json() -> f:format.raw()}

That's equal to:

<f:variable name="jsonData" value="{context: 'https://schema.org/'}" />
<f:format.raw><f:format.json>{jsonData}</f:format.json></f:format.raw>

(In your case I think you have jsonData already as the variable json, don't you?)

Upvotes: 0

Rudy Gnodde
Rudy Gnodde

Reputation: 4565

<f:format.raw>{</f:format.raw> should work. If not, you can also try <f:format.raw value="{" />. For example:

<f:format.raw value="{" />json<f:format.raw value="}" />

Upvotes: 1

Related Questions