July 17, 2007

HowTo: Creating static pages

Filed under: ZenMagick — DerManoMann @ 2:22 am

Even the most dynamic website includes some static pages. Usually those would contain stuff like contact details and other things that do not change often enough to justify creating a management interface (unless you are using a CMS, of course).

Stores are now exceptions to that rule and zen-cart offers two ways of managing static content:

  • Define pages
    A set of localizable files located in the zen-cart/includes/languages/english/html_includes folder (or a theme subfolder).
  • EZ Pages
    A somewhat more organized form with customizable title, grouping and TOC.

This post will look what is involved in creating a new define page.
Actually, there is embarrasingly little required to set up a new define page.

As an example, let’s create an About Us page.

  1. Create the new file
    This needs to be done manually, since zen-cart’s define page editor (under the Tools menu) does not allow to create new files. I would thing this is presumably due to the fact that zen-cart requires a new page handler for each define page and therefore creating the page doesn’t cut it.
    So, create a new file zen-cart/includes/languages/english/html_includes/define_about_us.php
  2. Edit
    Once the file exists, the define page editor will let you edit i, so it should show up in the list of define pages.
  3. Done
    Yep, that’s it!

The new static page is now accessible at the URL: http://[yourhost]/[pathtostore]/index.php?main_page=static&cat=about_us.

If you have pretty links enabled, the URL is: http://[yourhost]/[pathtostore]/static/about_us.

One thing to consider are the crumbtrail and page title. Since there is only the filename and contents to work with, the page title and crumbtrail are derived from the filename. The rules applied are:

  1. Strip the ‘define_’ prefix and ‘.php’ suffix
  2. Replace ‘_’ with space ‘ ‘
  3. Captialize words

Following that rule, the new About Us page would have a page title of (surprise!) ‘About Us’ and also a crumbtrail of Home :: About Us.

The last thing to keep in mind is, that ZenMagick allows PHP in define pages while zen-cart doesn’t. That means you can use all of ZenMagick’s link functions rather than hardcoding all URL’s into your files. (You could even display product information - even though strictly speaking that wouldn’t be static any more ;)

EDIT:

Of course, there is more than one way…

One feature of ZenMagick is that whenever a page is requested via a URL like ../index.php?main_page=xxx, the following happens:

  1. ZenMagick looks for a specific controller class that is responsible handling the request. This is done by generating a class name based on the main_page parameter. In this case the name would be ZMXxxController. If that class does not exist, XxxController is checked and if that fails as well, the default controller will be instantiated.
  2. The default controller will execute it’s processGet() method and as part of that generate a ZMView instance, also based on the value of main_page.
  3. If the view does exist, everything is fine and the page is displayed.
    Should the page not exist, the configured error page is returned.

So, based on the above, all that is actually required is to create a new view about_us.php in zenmagick/themes/default/content/views and off you go. The view will be availabe under ../index.php?main_page=about_us.

Downside is that the page is not maintainable via the admin interface. Generation of title and crumbtrail do follow the same principles as define pages.

Also it is important to note that in a default zen-cart setup you’ll have to create a corresponding folder includes/modules/pages/about_us. The alternative (preferred as there are a few views zen-cart doesn’t know about) is to disable zen-cart’s missing page check es you are right, that works as well. The alternative to doing that for each new view is to disable zen-cart’s missing page check (Configuration -> My Store -> Missing Page Check).

Of course, it is possible to add new controller too if additonal processing of the request is required. However, that is a topic for another HowTo…

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

You must be logged in to post a comment.