View previous topic :: View next topic |
Author |
Message |
TimJim Smarty Rookie
Joined: 22 Apr 2003 Posts: 14 Location: Germany
|
Posted: Mon Sep 22, 2003 4:11 pm Post subject: Display sizeof() of an assigned array before a section? |
|
|
Is there a possibility to display the sizeof() of an assigned array? I used an array for a section, but i couldn't find a way (without assigning only the size to another smarty variable) to display the size of the array before the section. After the section it can be display by {$smarty.section.customer.loop} or by {$smarty.section.customer.total}, but before the section this doesn't work. |
|
Back to top |
|
Troublegum Smarty Rookie
Joined: 07 Sep 2003 Posts: 33 Location: Germany
|
Posted: Mon Sep 22, 2003 4:20 pm Post subject: |
|
|
Try {$array|@sizeof} |
|
Back to top |
|
TimJim Smarty Rookie
Joined: 22 Apr 2003 Posts: 14 Location: Germany
|
Posted: Mon Sep 22, 2003 4:47 pm Post subject: |
|
|
Yes, thanx. This works. But where did you find this? I can't find it in the documentation... |
|
Back to top |
|
Troublegum Smarty Rookie
Joined: 07 Sep 2003 Posts: 33 Location: Germany
|
Posted: Mon Sep 22, 2003 5:31 pm Post subject: |
|
|
http://smarty.php.net/manual/en/language.modifiers.php
Quote: | If you apply a modifier to an array variable instead of a single value variable, the modifier will be applied to every value in that array. If you really want the modifier to work on an entire array as a value, you must prepend the modifier name with an @ symbol like so: {$articleTitle|@count} (this will print out the number of elements in the $articleTitle array.) |
And since you can use every php-function as a modifier, sizeof() or count() is no problem. |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Mon Sep 22, 2003 5:57 pm Post subject: |
|
|
Troublegum wrote: | And since you can use every php-function as a modifier, sizeof() or count() is no problem. |
This is very true and very handy! Just make sure you have $security turned off or if you have it turned on, that you set your security_settings array to explicitly list the php functions you want to enable as modifier functions. |
|
Back to top |
|
charly71 Smarty Rookie
Joined: 10 Jun 2003 Posts: 6
|
Posted: Wed Oct 22, 2003 10:50 am Post subject: section total seems not work... |
|
|
I can't write "No records found" when I've an empty section.
This is an example:
Code: | <ul>
{section name=i loop=$elenco}
{if $smarty.section.i.total lt 1}
<li>No records found</li>
{/if}
<li><a href="link.php?id={$elenco[i].IDrecord}">{$elenco[i].Title}</a></li>
{/section}
</ul> |
If I pass an empty array It doesn't return me "No records found". Why? |
|
Back to top |
|
andre Smarty Pro
Joined: 23 Apr 2003 Posts: 164 Location: Karlsruhe, Germany
|
|
Back to top |
|
charly71 Smarty Rookie
Joined: 10 Jun 2003 Posts: 6
|
Posted: Wed Oct 22, 2003 11:04 am Post subject: |
|
|
Great!
It works. Thank u andre!
(I must re-read smarty docs... ) |
|
Back to top |
|
|