Forums / Developer / 3.2 explode operator
Paul Forsyth
Thursday 11 September 2003 7:39:45 am
Im playing with the new template operators in 3.2 and have become a little stuck with 'explode'.
I was of the opinion that i could let through php functions via the template.ini file, then i noticed the lib file 'eztemplatearrayoperator.php' has the explode operator defined within it. But i can't seem to get it to work. Im trying to use similar syntax as the php function but all i seem to get are array_slice errors...
For example:
{let test="explode,test"|explode(",")} {section loop=$test} Item is:{$:item} {/section}{/let}
This gives the error:
array_slice(): The first argument should be an array in /var/www/html/3_2/lib/eztemplate/classes/eztemplatearrayoperator.php on line 441
I think i must be using the operator in a wrong way. How do i use it?
Paul
Gunnstein Lye
Thursday 11 September 2003 9:05:59 am
The explode operator is for arrays, not strings. Use it to split an array into two arrays. The input value must be an array, and the argument is an integer which specifies the split point. It returns an array containing the two resulting arrays.
It seems you have to use the template.ini approach.
Paul Borgermans
Thursday 11 September 2003 10:40:32 am
So the docs are wrong?
http://ez.no/developer/ez_publish_3/documentation/development/libraries/ez_template/operators/array_handling
-paul
eZ Publish, eZ Find, Solr expert consulting and training http://twitter.com/paulborgermans
Bruce Morrison
Thursday 11 September 2003 3:57:57 pm
After having a look at the code, the explode operator takes an offset and returns 2 arrays. The first array is an array of elements up to the offset and the second is the elements from the offset to the end. This is quite different to what is documented (as Paul has pointed out)
The documentation at http://ez.no/developer/ez_publish_3/documentation/development/libraries/ez_template/operators/array_handling indicates that many of the functions should be able to take both arrays and strings. From looking at the code at lib/eztemplate/classes/eztemplatearrayoperator.php this is not the case.
I think it is an excellent idea to produce documentation before the coding is done. That way it's done and the coders have something to work off and we don't end up in the situation where we are now (limited documentation).
One can only assume that these functions will be completed before the final release.
CheersBruce
My Blog: http://www.stuffandcontent.com/ Follow me on twitter: http://twitter.com/brucemorrison Consolidated eZ Publish Feed : http://friendfeed.com/rooms/ez-publish
Friday 12 September 2003 1:48:14 am
Yes, it seems the docs are wrong. I'll bug the others about this, we'll get it fixed before the release or change the docs.
Friday 12 September 2003 3:00:50 am
It was fixed yesterday, in fact. String support for explode has been added to svn and will be in the release. I'll see to that the docs are updated.
Friday 12 September 2003 3:39:53 am
Lovely. Thanks.