Building extensions - introduction

Building an extension for Sitemagic CMS is rather easy. Basically there is only a few rules to follow, and a few concepts to understand, to be able to write code for the Content Management System.


Two types of extensions

There are two types of extensions for Sitemagic CMS. Normal extensions, simply called Extensions, and Content Page Extensions, which are not really part of the framework, but a type of extension supported by the Content Page (SMPages) extension.

A normal extension is usually (but not always) available in the administration section from the Admin menu. Its content is being displayed in the content area of the website. This type of extension is used for all functionality in the administration section (settings for the contact form and gallery, administration section for the content pages and menu, and so on).

A content page extension is a piece of software that may be inserted into a content page from the page editor (TinyMCE). The gallery and contact form are both examples of extensions that also contain content page extensions. Several such content page extensions may be inserted on the same page.


Rules to obey - use unique names and IDs

In order to avoid conflicts with other extensions, it is important to use unique names and IDs for the following elements.

  • Class names (OOP)
  • URL paramenters
  • Sessions and cookies
  • JavaScript functions and variables
  • ID attributes for HTML elements and GUI controls
  • Style sheet classes
  • Data Sources
  • Attributes in the global attribute collection, if used
  • Place holders and repeating blocks in master template
In general it is a good idea to simply prefix the elements above with the name of the extension (the extension folder). The documentation will underline the need to use unique names or IDs when necessary.


Data types

When calling a function from the framework or another extension, the arguments specified for a particular function must be of exactly the types specified after the colon in the documentation.

GetData($id:string, $amount:integer)
Providing two strings in the function above will fail, even though $amount is a string containing the value "45". If necessary, cast the variable to the appropriate type. To learn more about how types are checked and handled, please read the chapter Strongly typed.