php operators

Author Message

Marc Boon

Friday 03 March 2006 6:21:56 am

I try to implement a php operator, but without success. The only documentation I could find about it is a comment in template.ini

What I need is a string replace function, like the php function str_replace.
So I added this to /settings/override/template.ini.append.php:

[PHP]
PHPOperatorList[replace]=str_replace

I hoped that something like this would work to create a url to the current node in another siteaccess, for a multilingual site (any other suggestions also welcome!):

{$node.url|ezurl(no)|replace('/eng/','/deu/')}

but the result is the same as without the replace() operat or.

I also tried this:

{replace('/eng/','/deu/',$node.url|ezurl(no))}

but then the result is 'Array'.

Mads Ovesen

Friday 03 March 2006 6:32:38 am

You can only use php operators that take one parameter: See http://ez.no/products/ez_publish/documentation/development/kernel/custom_template_operators
under limitations.

Instead you'll have to check your language in site.ini an make the url using the concat function.

/m

Marc Boon

Friday 03 March 2006 7:36:52 am

Problem with hardcoded urls is that it isn't portable between different configurations.
I used the ezurl() operator to automatically add the index.php(?) if needed. My development site runs on a machine with mod_php, and the production server uses CGI, so they need different urls.

Marc Boon

Sunday 05 March 2006 1:57:39 am

Just found exactly what I needed in Contributions:
http://ez.no/community/contribs/template_plugins/string_replace_operator

Thank you Alexandre Abric!

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.