PHP Macro

Last modified by Admin on 2024/07/22 00:14

php_file.icoRendering macro to execute PHP script
TypeJAR
Category
Developed by

Thomas Mortagne, XWiki Development Team

Active Installs32
Rating
0 Votes
LicenseGNU Lesser General Public License 2.1
Compatibility

Require XWiki 6.4 or more.

Installable with the Extension Manager

Description

Macro used as an entry point to execute PHP script. It's based on Quercus PHP engine and synchronized on its versions.

Usage

Unlike the other scripting languages available for XWiki, PHP is a semi-templating scripting language, which means that it must explicitly wrap code sections inside <?php ?> markers:

Parameters definition

See the Script Macro for details.

Example 1

{{php}}<?php echo 'Hello World!'; ?>{{/php}}

Result:
Hello World!

Example 2

Some *wiki* content.
{{php}} Some static content inside the PHP macro,
<?php echo("and some dynamic content."); ?> {{/php}}

Example 3

Calling Java methods.

{{php}}<?php echo($doc->getDocumentReference()); ?>{{/php}}

Result:
xwiki:CurrentSpace.CurrentDocument

Limitations

A current limitation of the Quercus library is that variables and class definitions are only valid inside the same macro block.

{{php}} <?php $i = 5; ?>
$i will be visible inside the same macro block:
<?php echo ($i); ?>
The correct value of i will be printed, 5.
{{/php}}

Unfortunately, here $i will not be valid:

{{php}} <?php echo ($i); ?> {{/php}}

Prerequisites & Installation Instructions

We recommend using the Extension Manager to install this extension (Make sure that the text "Installable with the Extension Manager" is displayed at the top right location on this page to know if this extension can be installed with the Extension Manager).

You can also use the manual method which involves dropping the JAR file and all its dependencies into the WEB-INF/lib folder and restarting XWiki.

Release Notes

v4.0.66

v4.0.65.1

v4.0.65

v4.0.63

v4.0.46

  • The extension is now a Contrib extension synchronized on Quercus versions.
  • Upgraded to Quercus 4.0.46

Dependencies

Dependencies for this extension (org.xwiki.contrib:macro-php 4.0.66):

  • org.xwiki.platform:xwiki-platform-rendering-macro-script 6.4
  • com.caucho:quercus 4.0.66

Get Connected