Forums / General / format a number
Claudia Kosny
Thursday 09 November 2006 1:35:38 am
Hi there
is there a way to format a number similar to PHP's number_format? I want to make sure that a certain number is always displayed with two decimals, a dot as decimal point and no thousand separator no matter what the locale is.The si operator requires a unit which I don't want and the l10n operator formats according to the locale as far as I know.
I can certainly write an extension which implements the number_format function of PHP in eZ but I was wondering whether this is possible using existing eZ operators.
Claudia
Xavier Dutoit
Thursday 09 November 2006 1:52:13 am
Hi Claudia,
The default way of adding a php function works only if you have one parameter to this function. I suppose that's not the case for you. I'm afraid it means creating an extension to add this template.
See this doc:
http://ez.no/products/ez_publish/documentation/development/extensions/template_operator
X+
http://www.sydesy.com
Thursday 09 November 2006 2:46:48 am
Hi Xavier
Writing my own extension for this is no problem at all, actually I have done so already meanwhile. I just was wondering whether there is a way to do it using existing eZfunctions as I don't want to add more custom code than necessary.
Thursday 09 November 2006 4:31:04 am
Hi,
You can add php functions as template function from within the template.ini.append
[PHP] # A list with php functions and their equivelant template operator names # Giving the operators a different name from the PHP functions # are recommended, that way you ensure that all operators follow # the same naming guidelines. It also means that you can change the # php function later on without doing template changes. PHPOperatorList[] PHPOperatorList[urlencode]=urlencode
The only problem is that you can then only use them as $blabla|urlencode() . If the php function you plan to use needs more than one parameter, then you need to write an extension.
Thursday 09 November 2006 4:34:12 am
BTW, could you add your function in the contrib ?