[TYPO3-mvc] viewhelper for first char register

Claus Due claus at wildside.dk
Thu Sep 15 18:20:11 CEST 2011


Hi Johannes,

It's fairly simple. You can use any value as the "string" argument - in your case I guess {hotel.name}.

You can place the ViewHelper anywhere, but I suggest the root of the "ViewHelpers" directory (since this is not a widget). You would use this by:

1) In the template, register the namespace for your ViewHelpers, fx {namespace hotel=Tx_Hotel_ViewHelpers}
2) Use <hotel:initialLetter string="{hotel.name}" /> in each iteration of your <f:for> - it will only render anything if the {hotel.name} starts with a different letter than the last time the <hotel:initialLetter> was used. Should be exactly what you need.

> Sorry for the dumb questions...

There's no such thing ;) ask away!

Cheers,
Claus

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

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