[TYPO3-mvc] viewhelper for first char register

Claus Due claus at wildside.dk
Thu Sep 15 15:15:27 CEST 2011


Hi Johannes,

Perhaps you can use this:

<?php

/**
 * Outputs a letter header if the passed letter is different from the last
 *
 * @package TYPO3
 * @subpackage Fluid
 * @version
 */
class Tx_Personnel_ViewHelpers_StartLetterViewHelper extends Tx_Fluid_Core_ViewHelper_AbstractViewHelper {
	
	/**
	 * Render a select
	 * @param string $string
	 * @return string
	 */
	public function render($string) {
		$letter = strtoupper($string{0});
		if ($this->templateVariableContainer->exists('initialLetter')) {
			$existing = $this->templateVariableContainer->get('initialLetter');
			if ($letter != $existing) {
				$this->templateVariableContainer->remove('initialLetter');
				$this->templateVariableContainer->add('initialLetter', $letter);
				return '<h4>' . $letter . '</h4>';
			}
		} else {
			$this->templateVariableContainer->add('initialLetter', $letter);
			return '<h4>' . $letter . '</h4>';
		}
	}
}
	

?>

You can (if you don't need the {initialLetter} Fluid variable) change to use $this->viewHelperVariableContainer->add() … etc. Just remeber that the ViewHelperVariableContainer requires a class name as first argument, the following arguments are just the same as for TemplateVariableContainer.

Cheers,
Claus

On Sep 15, 2011, at 3:09 PM, Johannes C. Schulz - EnzephaloN IT-Solutions wrote:

> Hello
> 
> 
> 
> I'm looking for a viewhelper (or partial) to enhance the alphabetical order
> by adding the first char as register. Maybe a thing like "group by first
> char" or something like that?
> 
> 
> 
> Output:
> 
> A             a thing with A
> 
>                Another thing with A
> 
> B             b.
> 
> L              last thing with L
> 
> Z             zzzz
> 
> 
> 
> Anyone ideas?
> 
> 
> 
> Best regards
> 
> Johannes
> 
> 
> 
> _______________________________________________
> TYPO3-project-typo3v4mvc mailing list
> TYPO3-project-typo3v4mvc at lists.typo3.org
> http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-project-typo3v4mvc



More information about the TYPO3-project-typo3v4mvc mailing list