Christian
Christian

Reputation: 229

Put fluid variable in data-attribute

I want to put a TYPO3 fluid variable into a data attribute to give informations to a modal box

I tride:

data-event-start='{ "year": "{event.start.year}", "month":"04", "day": "11", "hour": "18", "minute": "30", "second": "00" }'

The variable was interpreted as string.

What should I do to put the value of die variable into the json?

Upvotes: 1

Views: 895

Answers (1)

Mathias Brodala
Mathias Brodala

Reputation: 6460

The following should give you want you expected:

<f:alias map="{eventStart: {
  year: event.start.year,
  month: '04',
  day: '11',
  hour: '18',
  minute: '30',
  second: '00'
}}">

data-event-start='{eventStart -> f:format.json()}'

</f:alias>

You first create an array in Fluid here which can access variables as usual. For your data attribute you then format this to a JSON string.

Upvotes: 2

Related Questions