Building Pure PHP page extensions for Sitemagic CMS

In the previous chapter we went through the creation of a Pure PHP extension that takes up the full content area when rendered. But you can also add an extension to a content page within the page editor. We call this a page extension. This is both possible using an ordinary Sitemagic CMS extension, and a Pure PHP Extension.
The image below demonstrates how a page extension is added and displayed within the page editor. In this case we have added a contact form to our page.

/Extensions/PageExtension.png

Writing the code
Browse to extensions/SMPurePhp and create a file named HelloWorld.pageextension.php. The file must have the .pageextension.php suffix. To integrate it with Sitemagic CMS, simply use the $cfg configuration array as shown below.
HelloWorld.pageextension.php
<?php

// ====================================================================================

// Page extension title (shown in extension picker within page editor)
$cfg["Title"] = "Hello world";

// Page extensions are grouped under a category/headline - specify category title
$cfg["Category"] = "My Extensions";

// Extensions are displayed using a place holder image in the page editor.
// Specify its width and height in pixels below (without a 'px' suffix!).
$cfg["Width"] = "200";
$cfg["Height"] = "50";

// This file is executed multiple times during different stages of the life cycle.
// The render functionality below could potentially take some time to execute. It is
// therefore skipped if not needed. The check also prevents functions and classes from being
// redeclared. As these are now declared runtime, they cannot be called before declaration.
if ($render === true) {

// ====================================================================================

// YOUR CODE GOES HERE.
// Simply print/echo the code you wish to display within the content page.

echo "<div style=\"width: 200px; height: 50px; border: 2px solid red;\">";
echo "Hello world!";
echo "</div>";

// ====================================================================================

}

?>
Now open a content page for editing, click the extension button on the toolbar as shown on the image above, and add your new page extension to test it.