Rounded Corners for Mambo E-mail

How it works - The PHP

First the general principle.  We separate the 'what' we want to display from 'how' we display it.  The 'what' is the content, like modules and even the main component.  The 'how' is the structure, layout, presentation, css, images etc.

The 'what' is all in index.php what used to be the whole mambo template.
The 'how' is now in the patTemplate file, tmpl/page.html.

The index.php pushes data like the module content into the template to make it available for display.  The template engine is then used to draw (render) the template to the browser.

Confused?  Lets go over that slowly, looking at the example project, index.php

The first part of the file creates the template engine and loads template file.

// Create the template
$tmpl =& patFactory::createTemplate('');
$tmpl->setRoot(dirname( __FILE__ ) . '/tmpl');
$tmpl->readTemplatesFromFile( 'page.html' );

These lines:
  1. Create the template engine
  2. Tell the template engine where to find the template files. In this case ./tmpl
  3. Load the template file 'page.html' from the folder ./tmpl

The next section shows how to create content, and push it into the template engine as a variable.

ob_start();
mosShowhead();
$head = ob_get_contents();
ob_end_clean();
$tmpl->addGlobalVar('HEAD', $head);

These lines:
  1. Start the output buffer to capture all output instead of sending it to the browser
  2. Render the mambo html headers
  3. Capture the output to the variable $head
  4. Stop output buffering, and reset the output buffer.
  5. Push the $head variable into the template engine as Arketec - Rounded Corners for Mambo: Page 2

The next section does a similar thing for each module, buy calling the function ark_loadModules

ark_loadModules($tmpl, 'left', 'ark_page', 'LEFT');
ark_loadModules($tmpl, 'right', 'right', 'RIGHT');
ark_loadModules($tmpl, 'top', 'ark_page', 'TOP');

ark_loadModules is called once for each module that you want to load.  The ark_loadModules function uses the output buffering technique described above to capture the output of each module.

Read on to part 3 for an explaination of the template file, page.html


< Prev