I need to put an hour selection within a form, so I created a custom viewhelper which rounds the minutes to multiples of 5 only. in setup.ts I decalare the time;
lib.time = TEXT
lib.time {
data = date:H:i
}
in the template I call the cObject;
<nr:time value="{f:cObject(typoscriptObjectPath: 'lib.time')}" />
I tried it also inline which works (wrapped in random ViewHelper);
<f:link.action action="form">{nr:time(value: '{f:cObject(typoscriptObjectPath: \'lib.time\')}')}</f:link.action>
now I get to where I need it which has a condition and here I didn't find any syntax that worked ...;
<f:form.textfield property="date" class="date"
value="{f:if(condition: ticket.time, then: '{ticket.time}', else: '{f:cObject(typoscriptObjectPath: \'lib.time\')}')}" />
anyone who knows a good solution, maybe I started of completely wrong, maybe no viewhelper is needed but I could format and manipulate the time directly in the lib.
ps: this is the TimeViewHelper.php :
class TimeViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {
/**
* @param string $value
* @return
*/
public function render($value) {
$time = strtotime($value);
$m = date('i', $time);
$f = 5*60; // 5 minutes
$r = $time % $f;
$t = $time + ($f-$r);
$new_time = ($m == 0 || $m % 5 === 0) ? $value : date('H:i', $t);
return $new_time;
}
}
You can always use the f:if
condition with html syntax
<f:if condition="{ticket.time}">
<f:then>
<f:form.textfield property="date" class="date" value="{ticket.time}" />
</f:then>
<f:else>
<f:form.textfield property="date" class="date" value="{f:cObject(typoscriptObjectPath: 'lib.time')}" />
</f:else>
</f:if>