Re: alphabetical list with A,B,C headers?
| From: | Andr� Rabold | Date: | Thu, 05 Dec 2002 08:50:44 +0000 |
| Subject: | Re: alphabetical list with A,B,C headers? | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-6643@lists.php.net to get a copy of this message | ||
You could do something like the following:
{section name="idx" loop=$myArray}
{if substr($myArray[idx],0,1) != substr($myArray[idx.index_prev],0,1)}
<h1>{* PRINT HEADER *}</h1>
{/if}
{* PRINT ENTRY *}
{$myArray[idx]}
{/section}
It's not perfect because idx.index_prev is an invalid index for the first
item in array
but it should work. You could improve the script by first checking if an
previous
index exists.
André
<ssharma@amntv.com> schrieb im Newsbeitrag
news:Pine.LNX.4.44.0212041432570.5392-100000@webhost.amntv.com...
>
> Hello everyone,
>
> I'm rather new to smarty templates (been using PHPLIB for a while
> and was *blown* away at how easy Smarty is!!). Anyway I've got a list of
> product titles and I'm trying to print them out with their first letter as
> the header:
>
> --->A<---
> A Something
> Apples
> Axe
>
> --->B<---
> Blue
> Berries
> Bakers
>
> --->C<---
> etc....
>
> Any help would be fantastic!
>
> later,
> ajay
>