Implementing an automated site map


Why have an automated site map?

A site map can be a valuable aide that may help visitors to your site find their way 'round. When you site starts getting “deeper”, and you have many levels in your menus it will become increasingly difficult for your visitors to quickly see where they're going.

Keeping your site map up to date manually, however, can give you a hard time. It is easy to forget putting that quick last minute addition in your site map as well...

Enter phpCMS: from version 1.0.9 on, it allows you to automatically have a site map created for you. All you need to do is define the looks of your site map in a template, and from then on any changes to your site's structure will be automatically read from your menu file, and reflected in your site map.

Important: Your site map is cached on the server just like any other page! Therefore, in order to actually see changes you have made to your menu structure (and site map), you need to flush the server cache! Otherwise visitors to your site will be served those outdated files that are in the cache.


Setting up the Menu Template

The menu template is where you define the looks of your site map. This works very similar to the way you define the looks of the various menus. You can specify HTML that is to appear either before, next to, or after an item.

HTML code that is to appear before each item in your site map is preceded by a {field reference} that starts with “TOC” followed by a full stop “.”, followed by the name of the menu that is referenced (e.g. “MAIN”). The {field reference} ends with “PRE”.
Following this scheme, the field reference that indicates HTML that is to appear next to an item, ends with “NORMAL”, and the one indicating HTML that appears after an item ends with “PAST”

Suppose you wanted an entry in your site map that corresponds to the top level in your navigation hierarchy, you would write something like this:

{TOC.MAIN.PRE} <table>
{TOC.MAIN.NORMAL} <tr><td>{MNAME}</td></tr>
{TOC.MAIN.PAST} </table>

NOTE: Due to an as yet unfixed bug in the parser, the first field name of the menu that is referenced ( “MNAME” in our example) needs to be preceded by at least one character. Otherwise nothing would be shown in its place in the parsed page. In the example above {MNAME} is preceded by <tr><td>.

You can apply the scheme outlined above to all levels of your menu hierarchy accordingly.


Setting up the page template

You need to define an extra template for the site map (e.g. site.tpl). This template basically looks the same as a template for a regular content page. The site map is then included into this template by a {field reference} starting with “TOC”, followed by “CLASS” and the name of the menu class that is to be the starting point of the menu items shown.
This would look similar to the following:

<Your HTML code here> {TOC CLASS="00"} <Your HTML code here>

If you wanted to display submenu items starting at class 00.01 only, you would write:

<Your HTML code here> {TOC CLASS="00.01"} <Your HTML code here>

NOTE: A single space after “TOC” as well as the straight double quotation marks "" after “CLASS” are essential and need to be written this exact same way!

Within the site map template you are allowed to have multiple instances of {TOC CLASS=""} fields referencing either the same or different menu classes. This is necessary if, for example, you want to have a multiple column layout. In this case you would use HTML mark up to define where each main menu item should be displayed, and add a {TOC CLASS=""} field referencing the menu class you want displayed in each location.


Additional files

In addition to the modifications made to your menu template and the extra site map template described above, you will need:

Both project file and content file are created the same way as for a regular HTML page. Theoretically you might even create a dynamic template for the site map, in which case there would be no need for an extra project file. This is not advisable, however, since the use of dynamic templates prevents pages from being cached on your server, and adds significantly to the amount of time it takes to parse and display the site map.

The site map's project file contains the same paths and file references as your regular project file, except for the reference to the template to be used in your site map. You simply change this reference to the site map template you just created.

A content file is needed to display the actual site map. Within the content file you may have extra {CONTENT} fields e.g. for additional explanatory text. No special notation is needed here.