Published:
11 February 2010

Step 5. Optimize Page Handling

Symphony's got a great little trick up its sleeve when it comes to working with pages—you can assign "types" to them, and page types are totally open and extensible. You first saw page types in the "Hello World" tutorial, where we created a page with the type "index" to serve as our home page. Here, we'll use page types to keep our navigation menu clear of unwanted items and to serve a custom error page.

5.1. Introduce a Hidden Page Type

To keep unwanted pages out of our navigation, we'll assign them a special page type and use it to hide them. Let's hide the "Greetings Entry" page this way. Go to Blueprints > Pages and in the Title column click "Greeting Entry."

The Page Type field is empty. Underneath it you'll see a list of special page types used by the system. For this page, though, we'll invent our own. Enter hidden into the Page Type field and click Save Changes.

If you go back to your front end and view the ?debug interface, you'll see the change reflected in the navigation XML (Figure 8).

5.2. Update Your Navigation Template

Now all we need to do is update our navigation template to ignore pages with the 'hidden' type. Go to Blueprints > Utilities and click "master.xsl". Scroll down to the navigation template, and change the <xsl:apply-templates> element to:

<xsl:apply-templates select="page[not(types/type = 'hidden')]"/>

What we've done is add a predicate (the part between the brackets) to the XPath that says, "apply templates to page nodes that aren't of the type 'hidden'". Save your changes, and reload your home page. The "Greeting Entry" page should no longer appear.

5.3. Create a 404 page

In Step 4, we told our Greeting Entry data source to redirect to a 404 page when no results are found. If you go to http://your-site.com/greetings and fail to specify a title, you'll see Symphony's generic 404 page. Let's use page types replace that with one of our own.

Go to Blueprints > Pages and click the green Create New button. Give it a Title of Error and a URL Handle of error. For Page Type, click the small gray "404" link underneath the field, which will auto-enter 404 into the page type field. It's a special page type that Symphony will use when available to handle "Page Not Found" errors. Also click the "hidden" link. That'll keep the error page out of our navigation. The field's contents should be: 404, hidden. Attach the Navigation data source and click Create Page.

A blue Edit Template button should now appear in the upper right corner. Click it. As before, replace the default stylesheet shown with our modified starter template:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:include href="../utilities/master.xsl"/>

<xsl:template match="data">

</xsl:template>

</xsl:stylesheet>

We'll add some very basic content to the data template:

<xsl:template match="data">
    <div id="error" class="content">
        <h2>Sorry</h2>
        <p>Couldn't find what you were looking for. But have you seen our spiffy <a href="{$root}">home page</a>?</p>
    </div>
</xsl:template>

Save your changes. Now, if you visit any nonexistent URL, like http://your-site.com/horse-is-enemy-of-man, you'll see your custom error page.

Now, let's see about that "Add a Greeting" page.

Step 6. Enable Front-End Submission →

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details