This site has been archived and you can no longer log in or post new messages. For up-to-date community resources please visit ezplatform.com

eZ Community » Forums » Suggestions » PHP execution in templates
expandshrink

PHP execution in templates

PHP execution in templates

Saturday 26 July 2003 12:52:23 pm - 1 reply

From the many threads on how to execute php functions or scripts in templates it only seems right to provide a simpler way to do this than it is now. (At least for integrating old scripts to eZ publish)

Note: eZ publish will never support inline PHP in templates, the goal is to have a clear separation of code and design. And also to have better control over what is executed.

1.
Create a runscript template operator. It will take the scriptname as the first parameter and will look for the scriptname in a script repository. The rest of the operator parameters are optional arguments which are sent to the script.

Repositories are defined in a new .ini file and will also support extensions. This means that it's not possible execute arbitrary scripts/php-files in eZ publish, ie. it's safer.

The optional operator parameters can be defined to map to named php variables when the script is run. For instance the first optional parameter can be mapped to a variable called $name, etc.
The default behaviour is to have all optional parameters in a sequential array.

Any output of the script is returned from the operator as a single string. To catch the output the php functions ob_start(), ob_get_contents() and ob_end_clear() is used.

Example:
{runscript('ads.php',$node.id)}

It could also be possible to let runscript be a template function instead of an operator.

2.
Improve the eztemplatephpoperator operator. It was primarily meant to map simple modifying php functions to template operators. For example.
{$str|upcase}

I suggest adding support for sending all operator parameters as php function arguments. For this to happen the operator must be defined in the template.ini file to do so, if not the normal modifying behaviour is used.
For instance mapping php function rand to random operator.
{random(1,5)}

I also suggest a naming convention for these new operators so that they won't clash with new operators in future eZ publish releases.
The best way is perhaps to do automatic prefixing of operators, for instance prefix with php_.
{php_random(1,5)}
The prefix could be set in the template.ini file, so those who don't want it (and accept the consequences with future updates) can remove the prefix.

Friday 28 November 2003 1:48:16 pm

****************************
Create a runscript template operator
****************************

Could you please explain exactly how to create that new "runscript template operator" and where to place it.

thanks

Norman Leutner

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from