Skip to end of metadata
Go to start of metadata

Template Layout and Header Tags

A basic template layout structure has been introduced in osCommerce Online Merchant v2.2 to simplify the process of customizing the design of the catalog frontend.

Building the Template Layout

The template design layout is defined in catalog/includes/template_top.php and catalog/includes/template_bottom.php, with the page content existing in the base catalog files.

The final template layout is built with the following procedure:

  1. Base catalog file requested (eg, catalog/index.php)
  2. Application initialization through catalog/includes/application_top.php
  3. Control logic executed for actions performed
  4. Template design layout initialization through catalog/includes/template_top.php
  5. Page content loaded
  6. Template design layout finalized through catalog/includes/template_bottom.php
  7. Application finalized through catalog/includes/application_bottom.php

The outside structure of the design layout is specified in catalog/includes/template_top.php and catalog/includes/template_bottom.php, which, for compatibility to earlier osCommerce Online Merchant v2.2 releases, also utilizes catalog/includes/header.php, catalog/includes/footer.php, catalog/includes/column_left.php, and catalog/includes/column_right.php.

The default template layout is defined as:

catalog/includes/template_top.php
  • HTML doctype
  • Header/Meta tags
  • Page header (catalog/includes/header.php)
  • Page left column (catalog/includes/column_left.php)
Base catalog files (eg, catalog/index.php)
  • Page content
catalog/includes/template_bottom.php
  • Page right column (catalog/includes/column_right.php)
  • Page footer (catalog/includes/footer.php)

Header and Meta Tag Modules

As all base catalog files use the same catalog/includes/template_top.php file to define the HTML doctype, page title, and header tags, a modular header and meta tags implementation complements the template layout structure that allows page specific modules to define the page title and set additional header and meta tags.

The header and meta tag modules are located in catalog/includes/modules/header_tags inside sub-directories matching the name of the base catalog file (without the file extension), and are loaded in alphabetical order.

An example header and meta tag module is catalog/includes/modules/header_tags/product_info/title.php which adds the product name to the page title on the product information page.

If the base catalog file name is changed, the matching header and meta tag module sub-directory must also be renamed otherwise the modules will no longer load together with the page.

The header and meta tag modules must follow the following format:

<?php
  class ht_productInfo_title {
    function parse() {
      global $oscTemplate;

/* module specific code goes here */

      $oscTemplate->setTitle('New Page Title Name, ' . $oscTemplate->getTitle());
    }
  }
?>
Module Class Name

The module class name must be defined as:

ht_productInfo_title  
ht Short code for "Header Tag" to distinguish header and meta tag modules from other modules.
productInfo The name of the matching base catalog file in camel case form (without the file extension).
title The filename of the module (without the file extension).

Examples of modules include:

Filename Class Name
catalog/includes/modules/header_tags/create_account/module_name.php ht_createAccount_module_name
catalog/includes/modules/header_tags/index/module_name.php ht_index_module_name
catalog/includes/modules/header_tags/products_new/module_name.php ht_productsNew_module_name
Module parse() Method

The module must contain a static parse() method which contains the main code for the module, and must define $oscTemplate as a global variable to alter the header and meta tags for the page.

The oscTemplate class provides the following three methods to alter the tags for the page:

getTitle

Returns the current title of the page. By default the page title is defined by the TITLE language definition which is the name of the online shop.

$title = $oscTemplate->getTitle();

setTitle

Sets a new title for the page.

$oscTemplate->setTitle('New Page Title');

addHeaderTag

Adds a new header tag to the page.

$oscTemplate->addHeaderTag('<link rel="stylesheet" type="text/css" href="new_stylesheet.css" />');
Installing New Modules

New modules can be installed by copying the module files to the appropriate sub-directories in catalog/includes/modules/header_tags for the page they should be loaded for.

The modular implementation allows page specific header and meta tags to be altered without needing to edit core source code files.

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.