0

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;
    }
}
webman
  • 1,117
  • 15
  • 41
  • Please avoid `'{ticket.time}'` (wrapping object accessors with TextNodes). For more information see https://vimeo.com/167666466. – Claus Due Sep 07 '16 at 11:38

2 Answers2

4

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>
Dimitri L.
  • 4,499
  • 1
  • 15
  • 19
1

You do not say which version of TYPO3 and therefore Fluid you use. This answer applies to TYPO3v8 and Fluid Standalone:

<f:form.textfield property="date" class="date"
    value="{ticket.time -> f:or(alternative: '{f:cObject(typoScriptObjectPath: \'lib.time\')}" />

Even easier to express if you do yourself a favor and assign the lib.time as a template variable instead:

<f:form.textfield property="date" class="date" value="{ticket.time ? ticket.time : variableWithDefaultTime}" />
Claus Due
  • 4,166
  • 11
  • 23
  • I work with typo3 7.6.10 ... I tried to pass it directly but found only a way with static values ... this must be a new options in 8 ... – webman Sep 08 '16 at 05:00
  • I tried again to code inline after your vids ... thanks for the time you put into explaining to others ... but I could not get it to work ... '{ticket.date}' to ticket.date works – webman Sep 08 '16 at 05:58