|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
perate Smarty n00b
Joined: 24 Sep 2004 Posts: 2 Location: London
|
Posted: Sun Oct 03, 2004 7:41 pm Post subject: array count modifier problem |
|
|
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 |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Sun Oct 03, 2004 7:50 pm Post subject: |
|
|
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 |
|
perate Smarty n00b
Joined: 24 Sep 2004 Posts: 2 Location: London
|
Posted: Sun Oct 03, 2004 8:01 pm Post subject: |
|
|
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 |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Mon Oct 04, 2004 7:56 am Post subject: |
|
|
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 |
|
|
|
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
|