Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Display sizeof() of an assigned array before a section?

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
TimJim
Smarty Rookie


Joined: 22 Apr 2003
Posts: 14
Location: Germany

PostPosted: Mon Sep 22, 2003 4:11 pm    Post subject: Display sizeof() of an assigned array before a section? Reply with quote

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
View user's profile Send private message
Troublegum
Smarty Rookie


Joined: 07 Sep 2003
Posts: 33
Location: Germany

PostPosted: Mon Sep 22, 2003 4:20 pm    Post subject: Reply with quote

Try {$array|@sizeof}
Back to top
View user's profile Send private message
TimJim
Smarty Rookie


Joined: 22 Apr 2003
Posts: 14
Location: Germany

PostPosted: Mon Sep 22, 2003 4:47 pm    Post subject: Reply with quote

Yes, thanx. This works. But where did you find this? I can't find it in the documentation...
Back to top
View user's profile Send private message
Troublegum
Smarty Rookie


Joined: 07 Sep 2003
Posts: 33
Location: Germany

PostPosted: Mon Sep 22, 2003 5:31 pm    Post subject: Reply with quote

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
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Mon Sep 22, 2003 5:57 pm    Post subject: Reply with quote

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
View user's profile Send private message
charly71
Smarty Rookie


Joined: 10 Jun 2003
Posts: 6

PostPosted: Wed Oct 22, 2003 10:50 am    Post subject: section total seems not work... Reply with quote

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
View user's profile Send private message
andre
Smarty Pro


Joined: 23 Apr 2003
Posts: 164
Location: Karlsruhe, Germany

PostPosted: Wed Oct 22, 2003 10:56 am    Post subject: Reply with quote

Because your section won't loop on empty arrays. Use

{section}
...
{sectionelse}
No records found
{/section}

see http://smarty.php.net/manual/en/language.function.section.php
Back to top
View user's profile Send private message
charly71
Smarty Rookie


Joined: 10 Jun 2003
Posts: 6

PostPosted: Wed Oct 22, 2003 11:04 am    Post subject: Reply with quote

Great!

It works. Thank u andre! Laughing

(I must re-read smarty docs... Embarassed )
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP