Using PHP in a custom block

You can use PHP to customize your Developer Portal blocks. Using PHP to customize your blocks is an advanced option, and widens the customization capability of the Developer Portal.

Before you begin

You must have administrator access to complete this task.

You must also have prior PHP experience.

About this task

CAUTION:
Allowing the use of PHP can affect the security of your Developer Portal site.

Procedure

  1. Allow embedded PHP code to be evaluated in the Developer Portal:
    1. Click Modules in the administrator dashboard.
    2. Switch the PHP filter to ON.
    3. Click Save configuration.
  2. Configure the Developer Portal to use PHP code:
    1. Click Configuration in the administrator dashboard.
    2. Under the CONTENT AUTHORING heading, click Text formats.
    3. Click configure under the OPERATIONS heading for the PHP code row.
    4. Under the Roles heading, select the administrator check box. If you enable PHP code for a role, anyone in that role can execute PHP code. Do not enable this option for roles in which PHP code is not used to edit and configure blocks.
    5. Click Save configuration.
  3. Remove the WYSIWYG editor capabilities for PHP code:
    Note: The WYSIWIG editor is not compatible with PHP code, and must be switched off for PHP code.
    1. Select Configuration in the administrator dashboard.
    2. Under the CONTENT AUTHORING heading, click Wysiwyg profiles.
    3. Click Edit for PHP code.
    4. Expand the BASIC SETUP section.
    5. Deselect the Enabled by default check box.
    6. Click Save.
  4. Create a custom block for your PHP code:
    1. Select Structure in the administrator dashboard.
    2. Click Blocks.
    3. Click Add block.
    4. Assign a name and description to your new custom block.
    5. Under the Block body heading, use the Text format drop-down list to select PHP code.
    6. Optional: You can enter the PHP code manually by clicking Disable rich-text under the Block body heading. PHP tags should be used, as in the following example:
      <?php print "myCustomBlockCode"; ?>
    7. Click Save block.