Zen Cart, like most open-source code, is a largly undocumented.
Luckily for us, it also has a habit of mixing in much of it's
program/application logic with it's actual HTML design, so it's not
only undocumented, it's also hard to browse the HTML code. To top it
off, it also has a dynamic template loader, which means that the
program logic and HTML templates could be in any one of four different
directories. Also undocumented, and of dubious usefullness.
The result is that it's not only difficult to browse through the
program logic and HTML code, but you often don't even know which files
are going to get loaded.
This document is an attempt to sort through the overarching structure of how Zen Cart tends to work.
index.php steps:
Here's where all of action begins.
- it loads 'includes/application_top.php'
- if $main_page isn't set, it gets set to 'index'
- if the directory 'includes/modules/pages/$main_page' doesn't exist, $main_page gets set to 'index'
- it loads all of the files starting with 'header_php' in 'includes/modules/pages/$main_page'
- now it loads 'html_header.php' from the first first place it finds it from the following directories
- includes/templates/mytemplate/$main_page/
- includes/templates/template_default/$main_page/
- includes/templates/mytemplate/common/
- includes/templates/template_default/common/
- now it does the same thing for finding and loading 'main_template_vars.php'
- now it does the same thing for finding and loading 'tpl_main_page.php'
- Finally it displays the '</html>' tag. Why display it here when the '<html>' tag is displayed somewhere else? Who knows.
application_top.php steps:
This file will load in all of general definitions used site-wide,
initialize some site-wide classes ($template, $db) and do other general
stuff.
html_header.php steps:
The default
html_header.php file will simply create all of the HTML up to the </head> tag
It loads
'includes/modules/meta_tags.php', which uses a bloated switch statement to figure out what the site's title, meta-keywords, and meta-description should be.
It tries to find the css directory, and loads in it all stylesheets that begin with
'style' and end with
'.css'It does the same thing for the jscript directory, and tries to load all files that begin with
'jscript_' and end with
'.js'main_template_vars.php steps:
it simply sets $body_code to the first of:
- includes/modules/pages/$main_page/main_template_vars.php
- includes/templates/mytemplate/$main_page/tpl_{$main_page}_default.php
- includes/templates/template_default/$main_page/tpl_{$main_page}_default.php
- includes/templates/mytemplate/templates/tpl_{$main_page}_default.php
- includes/templates/template_default/templates/tpl_{$main_page}_default.php
that's it.
tpl_main_page.php steps:
this file lays out the basic page.
- <body>
- loads the 'includes/modules/header.php' file
- if the left column is enabled, it loads 'includes/modules/column_left.php'
- it loads the file set in $body_code
- if the right column is enabled, it loads 'includes/modules/column_right.php'
- loads 'includes/modules/footer.php'
- </body>
includes/modules/pages/$main_page/main_template_vars.php steps:
this
is where the meat of the actual content if loaded and displayed.
it typically does all of the program logic first, sets all of the
necessary variables, and then loads the template file. As usual, the
template file is loaded from the first of the following:
- includes/templates/mytemplate/$main_page/
- includes/templates/template_default/$main_page/
- includes/templates/mytemplate/templates/
- includes/templates/template_default/templates/
The standard is that the template file will be named
'tpl_SOMENAME.php'. Note that it doesn't end with
'_default.php'. The undocumented naming convention is that files that end with
'_default.php' are files that get loaded with it can't find the
'includes/modules/pages/$main_page/main_template_vars.php' file.
tpl_{$main_page}_default.php steps:
If it doesn't find the
above file and it instead finds a tpl_*_default.php file, then it means
that all of the program logic and variables will be mixed up with the
actual displayed HTML code. In Zen-Cart's defense, this generally means
that there's not a lot of program logic to be had here, hardly any
really, but it's still damn annoying to be mixing the program logic
with design. No sir, I don't like it one bit.
Future Updates
Eventually this document will also cover the process by which the program loads in the language files, such as "english.php" and the content files like "privacy.php" and "conditions.php."
The Zen Cart creators actually created these files with the idea that
they would be a part of your custom template, which is a clear
violation of the content/design seperation.
This document will also cover sideboxes (which requires a whole
nother custom template directory). As an interesting sidenote, when you
switch to a new template, all of the sideboxes get turned off. The
level of user-unfriendliness of Zen Cart is amazing to me sometimes.
This article is from: http://lifefeed.net/zencart/program_process.php