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

array count modifier problem

 
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 -> Plugins
View previous topic :: View next topic  
Author Message
perate
Smarty n00b


Joined: 24 Sep 2004
Posts: 2
Location: London

PostPosted: Sun Oct 03, 2004 7:41 pm    Post subject: array count modifier problem Reply with quote

Hi there I'm trying to write what it should be quite straight forward but doesn't seem to work for some reason

i've got the following file called modifier.count_array.php on my plugins directory

the file reads

Code:

function smarty_modifier_count_array($array)
{
    return count($array);
}


and I'm using it on the template as
Code:

{$myArray|count_array}

where did I go wrong?
Back to top
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Sun Oct 03, 2004 7:50 pm    Post subject: Reply with quote

read http://smarty.php.net/manual/en/language.modifiers.php

"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.)"
Back to top
View user's profile Send private message Send e-mail Visit poster's website
perate
Smarty n00b


Joined: 24 Sep 2004
Posts: 2
Location: London

PostPosted: Sun Oct 03, 2004 8:01 pm    Post subject: Reply with quote

Thank you, I realise is a rather silly plugin to implement but I thought I ought to start somewhere...

should this be a modifier or a function plugin? what is the general criteria? I read the documentation but I found scarce.

thanks again.
Back to top
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Mon Oct 04, 2004 7:56 am    Post subject: Reply with quote

there are no official general criteria.

as a starter:

- if you want to be able to use the output of the plugin as argument to another plugin, it has to be a modifier

- if you need a reference to $smarty inside the implementation of your plugin, it cannot be a modifier.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
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 -> Plugins 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