[TYPO3-mvc] Fluid and localized dates

Xavier Perseguers typo3 at perseguers.ch
Mon May 25 22:05:35 CEST 2009


Hi Sebastian,

>> I started using Fluid this morning and I really enjoy.
> :-)
> 
>> 1) Is there a plan to support localized dates? For instance adding a 
>> strftime method to the class and first converting the date as a 
>> timestamp and then passing it to strftime(). That may be not "correct" 
>> in all cases but should work quite well in most case (after all 
>> there's no 100% way with this)
> What is your use case for this? We still wanted to implement 
> configurable default values for ViewHelpers, so you could tell the 
> system (f.e. via some TypoScript) that if the page is English, use the 
> English timestamps, and for German, use german date/time notation.
> Would this solve your problem?

I guess so.

>> 2) How may I use the standard DateTimeViewHelper from my code, that is 
>> without using it in a template. I read that it takes only one 
>> argument, the format but the date to format itself is given as child. 
>> Should a syntax with an date attribute be added?
> Nope - actually you should not need to call a ViewHelper outside of the 
> Template. Why do you want to use it, and in what context?

I'm refactoring non-Extbase code with either hard-coded template or 
templating with marker (TYPO3 way) to use Fluid.

This is why I start making stuff step by step in order to let my code 
work until it's about 90-100% Extbase + Fluid.

I have a list of events to display. Each event has either a starting 
date and no ending date or both of them. I want to show those events 
grouped by year.

My template is something like that:

{namespace perso=Tx_MyExt_ViewHelpers}
<h2>{yearTitle} <perso:yearRange year="{year}"/></h2>
<table>
	<thead>
		<tr>
			<th>{descriptionHeading}</th>
			<th>{otherInfoHeading}</th>
		</tr>
	</thead>
	<tbody>
		<f:for each="{activities}" as="activity">
		<tr>
			<td>
				<strong><perso:dateRange start="{activity.startDate}" 
end="{activity.endDate}"/> :</strong>
				<perso:bbcode content="{activity.description}"/>
			</td>
			<td>
				<perso:bbcode content="{activity.otherInfo}"/>
			</td>
		</tr>
		</f:for>
	</tbody>
</table>

And in my controller I have a loop over all activities and first group 
them by year and then give each subset of activities to the Fluid 
renderer in order to get my output.

Currently my placeholders such as {yearTitle} are taken from 
locallang.xml and set with ->assign() but I'm pretty sure there's 
already some ViewHelper I did not find yet that allows specifying a key 
and a locallang.xml file, isn't it?

Now, concerning the dates, my dateRange renderer is as follows:

/**
  * Returns a formated range of dates.
  *
  * @param LocaleDateTime The start date
  * @param LocaleDateTime Then end date
  * @return string Rendered string
  */
public function render(LocaleDateTime $start, LocaleDateTime $end) {
	$content = '';
	
	if (!$start->isEmpty()) {
			// str_replace used to fix a bug in French locale
		$content .= str_replace('. ', '.', $start->strftime('%x'));
	} elseif (!$end->isEmpty()) {
		$content .= '?';
	}
	if (!$end->isEmpty()) {
			// str_replace used to fix a bug in French locale
		$content .= sprintf('%s%s', '-', str_replace('. ', '.', 
$end->strftime('%x')));
	}
	
	return $content;
}

This is why I used strftime... to get the %x format. But I agree that I 
could do all my stuff without an own class, using only DateTime (which I 
eventually will change btw).

The question is how in such case, may I use the DateTimeViewHelper? I 
don't understand. Or I should incorporate quite a lot of logic into my 
template to get the rendering be done the way I want, with <f:if> and 
<f:else> tags. Are you sure it makes sense? Or did I miss something?

-- 
Xavier Perseguers
http://xavier.perseguers.ch/en

One contribution a day keeps the fork away


More information about the TYPO3-project-typo3v4mvc mailing list