Transcript

Download and upzip the Pages app.

Place the folder perch_pages into perch/apps

Open perch/config/apps.php and link the runtime.


<?php
    include(PERCH_PATH.'/apps/content/runtime.php');
    include(PERCH_PATH.'/apps/perch_pages/runtime.php');
?>

Create a folder inside perch/templates called pages

In this folder we need to create a template for our new pages. I am going to allow my client to add new pages in the about section of the site. I don’t want to give them access to the root of the site to create millions of navigation items but they might want to add some new pages inside the about section. So I’ll use the current about page as a template. Open that in your editor.

In the perch_pages folder is an example template – you can find it in perch_pages/templates/example.php – open this in your editor for reference.

With the about/index.php page in your editor save a copy of this page as perch/templates/pages/about_template.php

We need to make a couple of changes to the template to make it usable as a template.

First edit the link to the Perch runtime at the top of the template to:


<?php 
  include($_SERVER['DOCUMENT_ROOT'].'/perch/runtime.php');
?>

You can copy this from the example template.

In the title element add: <?php perch_pages_title(); ?> again copied from the example template – this will mean the title can be dynamic.

Save the template.

Finally we need to make the about section of the site writable by the webserver – this will depend on your hosting configuration but the setting you use for the resources folder in Perch should work.

Now log into your Perch admin and you should see you have a link to the Pages app.

Before we start adding Pages we need to tell Perch which sections are allowed to have new pages added. Go into Settings and at the bottom of settings here you can see that I have a check box to set if I would like to allow editors to delete new pages – check this if you are happy about this. In the large textarea you can add any folders that pages can be created inside. Just add the paths one per line. In my case I just want the about section to be editable so I add /about here and submit the form.

Now click on the main Pages link and click View Page Templates. You should see your about_template template listed. Click on it. Here you can set options for the template.

The Copy Region Options setting lets you choose a page in your site where the regions will be copied from. This means that when your editor creates a new page they won’t have to decide what type of content template to use. The regions will already be set up for them and they can just add content. In our case we want to use about/index.php

The next setting lets you choose whether the reference this template (meaning that any changes to the template will be updated on any pages created from it) or copy the template (changes to the template will NOT be reflected on created pages). Generally I want to reference the template so I can keep all pages consistent.

Save the template settings and go back to the main page listing.

The final thing I want to look at before we actually add pages is Navigation Groups. In the sidebar click Navigation groups. These let you create different groups for navigation to live in – perhaps you want to create a set of pages in the footer of the site. I only want one group at the moment so I’m going to leave this as default – but it is worth remembering that you can add new groups or rename them here.

We can now add a page – I know it seems as if there has been quite a bit of setup but that only needs happen once – and of course your client never sees any of this – they can just add pages!

Click Add New Page.

Complete the form here giving the page a title, selecting the section, template (we only have 1 option but if you had several templates and sections editable you could choose here) also the Navigation group – note you can set a page to be hidden from Navigation. It will still be a page people can visit on the site but it won’t show up in any generated navigation.

Submit this form and your new page is created.

If you go back into Content you should see the page is listed and has the same regions as the about page. You can now click on any of those regions and edit the text.

Your new page will be found at about/history.php in the site – Perch makes created pages .php – if you are doing any URL rewriting you will need to make sure your rules account for newly created pages.

Creating Navigation

Open your template about_section.php and we can add a navigation listing. Replace the navigation list with the following PHP.


<?php 
$opts = array(
       'navgroup' => 'default',
       'from_path' => '/about',
       'levels' => 1
   );
perch_pages_navigation($opts); 
?>

So we are asking for the default navgroup, displaying from /about (so this will show subpages of about), and only one level – if you want to show subpages as nested levels of navigation increase this value.

Save the template and because you referenced the template, refreshing about/history.php will display the navigation. If we add an additional page it too shows up.

This function can be placed on other pages of your site, so to add the Navigation to the top level about page add it to about/index.php just in the same was as we created the template navigation.

You can now add new pages via Perch.

Perch by edgeofmyseat.com

Perch is a product developed and sold by edgeofmyseat Limited t/a edgeofmyseat.com Registered as a company in England and Wales, company registration no. 04735127