TYPO3 groupedFor viewhelper according to dates

2019-03-04 18:21发布

I have a simple model "item" with 3 properties: title, description, date

Now I want to have a list like this:

10.10.17:

title item 1

title item 5

12.10.17:

title item 8

and so on

According to groupedFor - grouping objects according to dates

I added a getter like

/**
 * Get day month year of datetime
 *
 * @return int
 */
public function getDayMonthYearOfDatetime()
{
    return (int)$this->datum->format('dmy');
}

My list view:

<f:groupedFor each="{items}" as="dayMonthYearOfDatetime" groupBy="dayMonthYearOfDatetime" groupKey="datum">
                <tr>
                    <th>{datum}</th>
                </tr>
                <f:for each="{dayMonthYearOfDatetime}" as="calendar">
                    <tr>
                        <td>{item.title}</td>
                    </tr>
                </f:for>
            </f:groupedFor>

Now I get the following output:

101017 title item 1 title item 5

121017 title item 8

How to diplay the correct date "10.10.17" instead "101017"?

If I change my getter to:

    return (int)$this->datum->format('d.m.y');

It doesn't work.

3条回答
别忘想泡老子
2楼-- · 2019-03-04 18:38

You can simply use the real date object of the first group-item.

So it would be

<f:format.date format="d.m.Y">{dayMonthYearOfDatetime.0.datum}</f:format>
查看更多
放荡不羁爱自由
3楼-- · 2019-03-04 18:39
return (int)$this->datum->format('d.m.y');

Remove the (int)

查看更多
来,给爷笑一个
4楼-- · 2019-03-04 19:00

You can't expect to have a grouping if you return int from a date-string with dots.

Either you need to return string (but I don't know whether the function is allowed to return anything else than int) or you need to calculate your datestring from the calculated integer.

Try a viewhelper which does integer caclulations ( % 100, / 100 %100, /10000) or simple substrings (,0,2 ,2,2 ,4,2) to extract the values for day, month, year for a following concatenation.

查看更多
登录 后发表回答