The getContent()

by Luke Simpson | Last edited: 5/16/2011

The getContent() is a php function that gets content from the CMS and displays it on the web page. It is the heart of the API and the workhorse that retrieves data from records in the database based on a predefined set of parameters that you provide.

The Require

For the getContent() and other CMS functionality to work, the following statement needs to be at the top of every template:

<?php require($_SERVER[“DOCUMENT_ROOT”].”/monkcms.php”); ?>

The monkcms.php file handles a number of important duties, most importantly setting up the getContent() function. You do not need to do anything to this file except require it.

Anatomy of the getContent()

Figure 1thegetcontent-fig1

  1. Module Name
  2. Display Type – list, detail or auto
  3. Parameters – used to filter, set list order, specify number of records to return, etc.
  4. Show – controls the actual output. Can and should include proper HTML tags, with attribute and any other double quotes escaped (preceded with "\").
  5. API tags (highlighted) – brings in the specified item of data for that particular record.

Other notes:

  • Each piece of the getContent must be wrapped in quotes and must end with a comma.
  • The module name must always be the first parameter listed. Other than that, the order of parameters does not matter. "Show" parameters will always output in the same order they appear, but different show types will be grouped. For instance, all before_show tags will be displayed before any show tags.
  • If there is no data that exists for the record's API tag, that line of code that calls it will not be returned. Example: if there is a line in an Article getContent() like this: "show:<p>__author__</p>", the entire line for that record (including the paragraph tags) will be removed if no author was specified for the Article. This helps to avoid outputting empty HTML tags.
  • You don’t need to put each piece on it’s own line, but it is recommended for readability.
  • You can include more than one getContent call within the php tags, as well as additional php commands.
  • You may use newlines (\n) and tabs (\t) to format the HTML output to match your template HTML.

Full API Reference

"Copy-friendly" version of the above getContent():

<?php getContent(
   "show:<div class="article">",
   "show:t<p>Posted: __date format='F j'__</p>",
   "show:t<p>__preview limit='180'__</p>",


Next Article >> URL Paths