Creating new pages

From Zen Cart(tm) Wiki
Jump to: navigation, search

Contents

Overview

You may want to add additional pages to your Zen Cart™ store. Here are the basics steps you should follow. We will assume your new page is named myNewPage.


Components of the new page

In order for the Zen Cart™ system to pick up the new page, you will need to include four components:


  • A new directory, includes/modules/pages/myNewPage/, containing a file called header_php.php
  • A new file in the directory includes/templates/template_default/templates called tpl_myNewPage_default.php
  • A new file, includes/extra_datafiles/myNewPage.php, defining your new page's filename for the Zen Cart™ system
  • A new language file, includes/languages/english/myNewPage.php


Naming your files

It's important that all these new components use the same name for your new page. (The only partial exception is the extra_datafiles file; see below.) Be sure that your new pages directory name, language file name, and template file name use exactly the same name for your new page.


The header_php.php file

At a minimum, this file should contain the following:

<?php
//
// +----------------------------------------------------------------------+
// |zen-cart Open Source E-commerce                                       |
// +----------------------------------------------------------------------+
// | Copyright (c) 2006 The zen-cart developers                           |
// |                                                                      |
// | http://www.zen-cart.com/index.php                                    |
// |                                                                      |
// | Portions Copyright (c) 2003 osCommerce                               |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.0 of the GPL license,       |
// | that is bundled with this package in the file LICENSE, and is        |
// | available through the world-wide-web at the following url:           |
// | http://www.zen-cart.com/license/2_0.txt.                             |
// | If you did not receive a copy of the zen-cart license and are unable |
// | to obtain it through the world-wide-web, please send a note to       |
// | license@zen-cart.com so we can mail you a copy immediately.          |
// +----------------------------------------------------------------------+
// $Id: header_php.php $
//
  require(DIR_WS_MODULES . 'require_languages.php');
  $breadcrumb->add(NAVBAR_TITLE);
?>


Additionally, you can add in whatever processing you need to do on your page to this file. Have a look at the other pages in the includes/modules/pages/ directory to get an idea of what this file is for.


The template file

The new template file, includes/templates/template_default/templates/tpl_myNewPage_default.php, contains the main HTML body for your page. A good starting point for this page is to copy one of the other pages in this directory and adjust it to fit your new page's desired format.


Info.png Custom templates
You can copy your new template page from template_default to a custom template directory if you'd like to make template-specific changes to the layout (for example, for a seasonal design).


The extra_datafiles file

This file, includes/extra_datafiles/myNewPage.php, should contain the following line:


<?php 
define(FILENAME_MYNEWPAGE, 'myNewPage');
?>


The constant on the left, FILENAME_MYNEWPAGE, is the tag you will use to link to your new page from other locations in your shop. The string on the right, myNewPage, must exactly match the name of your new includes/modules/pages/ directory.


Info.png Just one new file
You don't need a separate new extra_datafiles file for each new page you create. If you are adding several new pages, you can place all the filename defines into one file, and give that file any name whatsoever. All the files in the extra_datafiles folder are loaded in for every page.


The language file

The language file for your page should contain definitions for all the local text elements on your page; for example:


<?php
define('NAVBAR_TITLE', 'New Page');
define('HEADING_TITLE','My Cool New Page');
?>


Info.png Other languages
Don't forget to make a copy of the language file for the other languages in your shop.


Creating the link

One way that you can link to the new page you created is using HTML -- for example, in a product description. The syntax for this method is:

<a href="index.php?main_page=myNewPage">Visible link text</a>

The name will match the directory you created within the pages directory when creating your header_php.php file.


Optional files

You have several other options for your new page. You could create new CSS classes for your page, for example, and save these in the file includes/templates/template_default/css/stylesheet_myNewPage.css. Or you could make override copies of tpl_main_page for your new page.

Personal tools