Home > Back-end >  How to access objects of date/time (like date.H) in for if-else statement (TYPO3)
How to access objects of date/time (like date.H) in for if-else statement (TYPO3)

Time:12-23

For an if-else statement, I am trying to access individual objects of the time class in TYPO3 (9.5) but this is apparently not easily possible.

The classes are startdate and enddate. In my case, the output is as follows:

<f:format.date format="%d.%m.%y %H:%M">{event.startdate}</f:format.date>

Now I should actually be able to access e.g. %H in order to be able to set this as a condition like:

<f:if condition="{event.enddate.M} != '00'">
    <f:then>A</f:then>
    <f:else>B</f:else>
</f:if>

but I cannot access these values via event.startdate.H or something similar. I have already tried to tackle it with Viewhelper, but I didn't get anywhere with it either:

<v:condition.string.contains haystack="{event.startdate}" needle="00">
    <f:then>A</f:then>
    <f:else>B</f:else>
</v:condition.string.contains>

Does anyone have an idea where I have a thinking error or how this might be solved?

CodePudding user response:

You can just feed the enddate to the format.date ViewHelper in order to get the parts you need, so your condition could look like this:

<f:if condition="{event.enddate->f:format.date(format:'%M')} != '00'">
    <f:then>A</f:then>
    <f:else>B</f:else>
</f:if>

Your line <f:format.date format="%d.%m.%y %H:%M">{event.startdate}</f:format.date> only changes the rendered content, it does not manipulate your actual data.

  • Related