Module Templates

From Snapp CMS Developer Documentation

Jump to: navigation, search

Module templates control the look and feel of individual pages.

When a new page is created, it has a module, and a corresponding module template associated with it. Each module has one or more actions associated with it, and template folders contain view files for each action.

The default module templates for any given module is located in:

/templates/default/modules/MODULE_NAME/templates/default/

Typically, master templates contain module-specific elements, including:

  • Module content layout code
  • Module/page-specific media, CSS and Javascript
  • Common navigation components for a given module

Structure

The typical template contains the following file structure:

  • css/
    • default.css
Module-specific CSS file
  • images/
Module-specific images
  • javascript/
Module-specific JS
  • ACTION.php
The HTML view file for the specified action of the module (as determined by the module controller script. e.g. Standard content module templates have only one action - "index", and so each module template only contains index.php. The blog module on the other hand has the actions "article", "articles" and "index", and so would have article.php, articles.php and index.php

Basic Module-specific HTML Template

The following is an example of a basic HTML template for the Standard Content module, located in DOCUMENT_ROOT/templates/default/modules/content/templates/default/index.php (See Side_Menus for more information about Side Menus):

<h1 class="moduleTitle"><?php echo $content->title?></h1>
<div class="sidemenu">
<?php
 	if ($cms->page->sidemenu > 0) {
		echo '<h4>Pages in this Section</h4>';
		echo $cms->loadMenu('Basic',
                                    array(
                                          'menu_id'=>$cms->page->sidemenu,
                                          'class'=>'Tips',
                                          'singleLevel'=>false
                                         )
                                   );
	}
?>

</div>
<div class="moduleContent">
	<?php echo $content->content) ?>
</div>

Note that the variable $content is supplied to the template from the module's controller script, DOCUMENT_ROOT/templates/default/modules/content/index.php, which looks as follows:

<?php
/*************************************************************************************************
	Standard HTML Content Module
**************************************************************************************************/

// Check if this file is being included and NOT accessed directly

	if (!isset($cms)) {header('Location: /error/invalid_access.html');}
	if (!empty($cms->page->module_id)) {
		$content = new moduleContent($cms->page->module_id);
		include($cms->getModulePath().'index.php');
	} else {
		header('Location: /error/missing_page_id.html');
	}
?>
Personal tools
Core Components
Standalone Installs