Follow

How do I use PHP in the CMS?

While the CMS enables any individual the ability to create a web page without knowing PHP, you can also apply PHP to a web page. Open the WYSIWYG Editor and click on the Source Code tool.


The members of Web & Digital Communications are happy to help with basic troubleshooting for our advanced users, however it is not our place to actually teach you how to write code. Here are three resources we recommend to help you get going writing your own PHP:

 

Before converting your page or creating new PHP code within your web pages, consider the complexity of your code. Simple PHP (limited to a small section with no header includes) can be placed inline if special precautions are taken. More complex PHP source code must be included within the page from extra file includes or assets.

All content placed directly in the page source must be XML compliant. For PHP this means:

  • All PHP must use the following for enclosing tags:
    <?php ... ?>
    Do not use:
    <? ... ?>
  • Inline echo statements should use the following:
    <?php echo $var; ?>
    Do not use:
    <?=$var?>
  • If you use functions that use less than (<) or greater than (>), your XML will need to be validated using &lt; and &gt; tags.
  • We recommend length PHP code be placed into its own uploaded and published PHP file and require_once’d in a CMS web page.

 

Simple PHP

If your PHP is very simple (e.g. echos out one variable, date, or similar) try placing it inline using Code Protect. If you have trouble, please follow the guide for using complex PHP below.

 

Complex PHP

  1. Upload your finalized .php file into the CMS.
  2. Publish your .php file.
  3. Create a Source Code Asset, locked to your site, that will reference the PHP you just published. For help with this visit How do I create a Source Code Asset?.
  4. Edit this Asset and include standard PHP to include the file you just created. The file path is local to where the asset will be referenced.
    <?php require_once("fancyinclude.php") ?>
  5. Publish your Asset.
  6. Now you may reference this PHP code from a .pcf file:
    • For PHP includes that come before the head, be sure to turn on the Preprocessor from your page properties. If you are unable to see this option please submit a request. Click Edit Preprocessor near the bottom of your page when you are in edit mode.
    • For includes within the body of the page, simply click Edit Main Content when you are in edit mode.
  7. Insert your newly-created Asset, save, and publish. 
  8. Wait a moment for your files to publish, files can take up to a minute to publish to our server.

 

Troubleshooting

File Not Found Errors

Be sure to publish all Assets, PHP files, and .pcf files in order for PHP to work correctly. Remember publishing can take up to a minute as the file is placed onto our server.

If you skip using an external .php file and place your PHP code into the Asset, it will need to be XML compliant. All instances of <? shorthand must be changed to <?php and so forth.

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request
Powered by Zendesk