[TYPO3-mvc] viewhelper for first char register

Johannes C. Schulz - EnzephaloN IT-Solutions info at enzephalon.de
Thu Sep 15 16:33:20 CEST 2011


Hey Claus

Thanx a lot! It looks good, but I have to play around until it will work, I think...
My object is "hotel", so the call is {hotel.initialLetter}, or?
I place the php file in the ViewHelpers folder or in ViewHelpers/Widget?
And I have to change templateVariableContainer to MyObjectClass?

Sorry for the dumb questions...

Best regards
Johannes

-----Ursprüngliche Nachricht-----
Von: typo3-project-typo3v4mvc-bounces at lists.typo3.org [mailto:typo3-project-typo3v4mvc-bounces at lists.typo3.org] Im Auftrag von Tim Schoch | GSTALTIG
Gesendet: Donnerstag, 15. September 2011 15:21
An: TYPO3 v4 MVC project
Betreff: Re: [TYPO3-mvc] viewhelper for first char register

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