Creating Add-ons

From Contensive Wiki
Revision as of 16:23, 2 July 2015 by Admin (Talk | contribs) (Created page with "An Add-on is a data record that contains all the elements necessary to create a feature for a Contensive website. These elements include html, images, javascript, styles, serv...")

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

An Add-on is a data record that contains all the elements necessary to create a feature for a Contensive website. These elements include html, images, javascript, styles, server-side scripting (Jscript, VBScript, php, etc) and others.

Add-ons are packaged and distributed in add-on collections. Collections are compressed files (zip format) that include an xml format collection installation file and all resource files required for the add-on. The collection installation file guides a sites installation of a group of features, which may include one or more add-ons, as well as database indexes, database table descriptions, database records, and others.

An example of an add-on is the 'webcast and podcast' Add-on. When installed, it adds a "webcase" tab to the edit screen for each page. Upload a media file in that tab and the page displays the file automatically. Download the RSS Feed Add-on and adding this page to the RSS feed will automatically include the necessary entries to make the media file a podcast.

How Add-ons Are Executed

An Add-on can be run several ways. You control this when editing the add-on in the "Placement" tab.

  1. Dropped on a page: If an add-on is marked "Place on Page" or "Place on Template" it can be added to any page (or template) by any content manager through the wysiwyg editor. An example would be the Personalization Add-on. Administrators drop the add-on on a page and set it to First Name. When a visitor views the page, the add-on is replaced by it's output, in this case the visitor's first name.
  2. Added to every page in several specific locations: Add-ons can be set to run on every page at the start of the body, end of the body, start of the content or end of the content. Add-ons triggered at the end of the body have programmatic access to all the body content so they can act as filters. An example of this is the tool-tip Add-on. It runs at the end of the body on every page. It reads in the complete body html and modifies it to include tools tips under certain conditions. It returns the modified body to the
  3. As a remote method: If an add-on is marked as a remote method, it can be called remotely with it's name as the URL. A common example of a remote method add-on is the server-side work required for an ajax method, such as the method used to open folders in the admin navigator.
  4. As a background process: Any add-on can be executed as a background process. In this case, it's output is discarded. An example of a process add-on is the Contensive Content Spider. Periodically, it is started as a background process. It opens an HTTP interface and fetches a page from the site. It processes the reply from the site to check for errors, and to index the content it finds. There is an example of a process addon in the Add-on Samples collection in the Collection Library. Every minute, it updates the admin site header name.
  5. As a programmatic subroutine: Any add-on can be called by any other add-on. For instance, the Process Payment add-on can be called from the Shopping Cart Add-on, the MeetingSmart Add-on or any custom add-on that needs to process payments. To make sure the subroutine addon is installed, their should be an importcollection line in the calling collection.

Using Inline Scripts

Inline Scripts is a method of adding script programs in languages like php to add-ons. Inline scripts can be placed anywhere on the page, but are executed after the page is rendered by Contensive and returned to the webserver's scriting environment.

Simple Rules

  • Do not start and end with the script with the script's escape sequence, like <$PHP.
  • Use the return command to place a string where the add-on was placed.
  • You can use a function(), but it is not needed. If you include your code in a function, end the script with: return myFunction()
  • You can use any of the script language's context objects and functions, as well as the Contensive cp object.

Example

  1. Create a new add-on
  2. Give it a name
  3. In the placement tab, check In Content
  4. In the Inline Script tab, add this: return $cp->user->name
  5. edit a page and place the addo-n on the page
  6. View the page and the add-on shows thier name