[TYPO3-mvc] viewhelper for first char register

Tim Schoch | GSTALTIG tim.schoch at gstaltig.ch
Thu Sep 15 15:21:06 CEST 2011


Wrong mail address ;)
  _____  

From: Claus Due [mailto:claus at wildside.dk]
To: TYPO3 v4 MVC project [mailto:typo3-project-typo3v4mvc at lists.typo3.org]
Sent: Thu, 15 Sep 2011 15:15:27 +0200
Subject: Re: [TYPO3-mvc] viewhelper for first char register

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
  
  _______________________________________________
  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