Skip to content

Instantly share code, notes, and snippets.

@daKmoR
Created July 25, 2011 09:12
Datemenu for News2
<div class="news2 news2-datemenu">
<ul>
<f:groupedFor each="{news}" as="newsByYear" groupBy="yearOf{dateField}" groupKey="year">
<f:if condition="{settings.datemenu.year}">
<li class="{f:if(condition: '{year} == {overwriteDemand.year}', then: 'active year', else: 'year')}"><f:link.action pageUid="{listPid}" arguments="{overwriteDemand:{year: year}}">{year}</f:link.action>
<ul>
</f:if>
<f:groupedFor each="{newsByYear}" as="newsByMonth" groupBy="monthOf{dateField}" groupKey="month">
<f:if condition="{settings.datemenu.month}">
<n:ifOr condition="{settings.datemenu.monthforceShow}" condition1="{year} == {overwriteDemand.year}" condition2="{year} == {currentNewsItem.yearOfDatetime}">
<li class="{n:ifOr(condition:'{0:year, 1:month} == {0:overwriteDemand.year, 1:overwriteDemand.month}', condition1: '{0:year, 1:month} == {0:currentNewsItem.yearOfDatetime, 1:currentNewsItem.monthOfDatetime}', then: 'active month', else: 'month')}">
<f:link.action pageUid="{listPid}" arguments="{overwriteDemand:{year: year, month: month}}">
<f:translate key="month.{month}" /> {year} (<span class="news2-datemenu-count"><f:count subject="{newsByMonth}" /></span><f:translate key="{f:if(condition: '{f:count(subject: newsByMonth)} == 1', then: 'entry', else: 'entries')}" />)
</f:link.action>
</n:ifOr>
</f:if>
<f:if condition="{settings.datemenu.newsItem}">
<n:ifOr condition="{settings.datemenu.newsItemforceShow}" condition1="{0:year, 1:month} == {0:overwriteDemand.year, 1:overwriteDemand.month}" condition2="{0:year, 1:month} == {0:currentNewsItem.yearOfDatetime, 1:currentNewsItem.monthOfDatetime}">
<f:if condition="{f:count(subject: newsByMonth)} >= 1">
<ul>
<f:for each="{newsByMonth}" as="newsItem">
<li class="{f:if(condition: '{newsItem} == {currentNewsItem}', then: 'active newsItem', else: 'newsItem')}">
<n:link action="detail" arguments="{newsItem: newsItem, settings: settings, overwriteDemand:{year: year, month: month}}">{newsItem.title}</n:link>
</li>
</f:for>
</ul>
</f:if>
</n:ifOr>
</f:if>
<f:if condition="{settings.datemenu.month}">
<n:ifOr condition="{settings.datemenu.monthforceShow}" condition1="{year} == {overwriteDemand.year}">
</li>
</n:ifOr>
</f:if>
</f:groupedFor>
<f:if condition="{settings.datemenu.year}">
</ul>
</li>
</f:if>
</f:groupedFor>
</ul>
</div>
<?php
/* *
* It is free software; you can redistribute it and/or modify it under *
* the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation, either version 3 of the License, or (at your *
* option) any later version. *
* *
* This script is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
* TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser *
* General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with the script. *
* If not, see http://www.gnu.org/licenses/lgpl.html *
* *
* The TYPO3 project - inspiring people to share! *
* */
/**
* This view helper implements an if/else condition, where multiple conditions can be supplied which will be placed as or to each other
* @see Tx_Fluid_Core_Parser_SyntaxTree_ViewHelperNode::convertArgumentValue() to find see how boolean arguments are evaluated
*
* <n:ifOr condition="{rank} > 100" condition1="{level} > 10">
* Will be shown if rank is > 100 or level is > 10
* </n:ifOr>
*
* @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
*/
class Tx_News2_ViewHelpers_IfOrViewHelper extends Tx_Fluid_Core_ViewHelper_AbstractConditionViewHelper {
/**
* renders <f:then> child if $condition is true, otherwise renders <f:else> child.
*
* @param boolean $condition View helper condition
* @param boolean $condition1 View helper condition
* @param boolean $condition2 View helper condition
* @param boolean $condition3 View helper condition
* @return string the rendered string
* @author Thomas Allmer <at@delusionworld.com>
*/
public function render($condition, $condition1 = false, $condition2 = false, $condition3 = false) {
if ($condition || $condition1 || $condition2 || $condition3) {
return $this->renderThenChild();
} else {
return $this->renderElseChild();
}
}
}
?>
plugin.tx_news2.settings {
datemenu {
year = 1
month = 1
monthforceShow = 0
newsItem = 0
newsItemforceShow = 0
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment