Tips & Tricks: Vol 1

Integrate Collections in Perch Blocks

By Scott Gruber

Ever wonder if the <perch:related> tag could be used to relate a collection in a page using blocks? I did, and posted in the Perch Support Forum to see if was possible. Drew, lead developer of Perch and Perch Runway replied with an encouraging bit of advice: try it out. So I did. It worked!

So now we can quickly build relationships between a page with Blocks and a Collection. I’ve used the technique to connect authors, articles and centers as related content.

I shared the code for the two templates on a GitHub Gist if you’d like to take a look at the setup and grab it.

Show:all

By Clive Walker

The <perch:showall /> tag can be added to any Perch (.html) template to show the content available for use. It will output a table with the ID of the content and the content itself.

For example, if using perch_content_custom for retrieving/filtering data, use <perch:showall /> tag in your template to check the data is available.

For example, use in Blog app post.html template to see the available data (including fields that Perch generates that you wouldn’t otherwise know).

Remove the tag for production.

Config Buckets

By Simon Cox

You can set up your Configs to work in different locations. Once set up you do not need to remember to keep changing passwords and paths when you deploy.

You do this by setting up different cases:

case('mysite.local') :

case('mysite.my-staging-server.com') :

default :

The default should be your production site with local and UAT sites for the other two.

So you get something like:

switch($http_host)
{
    case('mysite.local') :

        define("PERCH_DB_USERNAME", 'root');
        define("PERCH_DB_PASSWORD", 'xxxxxx');
        define("PERCH_DB_SERVER", "localhost");
        define("PERCH_DB_DATABASE", "db-site1");
        break;

    case('mysite.my-staging-server.com') :
        define("PERCH_DB_USERNAME", 'staging_username');
        define("PERCH_DB_PASSWORD", 'staging_password');
        define("PERCH_DB_SERVER", "localhost");
        define("PERCH_DB_DATABASE", "db-staging-database");
        break;

    default :
        define("PERCH_DB_USERNAME", 'mysite_user');
        define("PERCH_DB_PASSWORD", 'mysite_password');
        define("PERCH_DB_SERVER", "localhost");
        define("PERCH_DB_DATABASE", "db-mysite");
        break;
    }

Full instructions from Rachel on the Perch website

Amending Navigation for Single Page Applications

By Sarah Tevendale

If you‘re building a site with full height images at the top when moving between different page it can be useful to set your navigation to hit the section under the first image, especially if the image at the top is shared over more than one page. this can easily be achieved by editing your navigation template and adding the id of the section you want users to jump to. In the following example, the user will skip straight to the part of the page with the ID of "main-content" and miss anything above.

<perch:before>
    <ul>
</perch:before>
        <li<perch:if exists="current_page"> class="selected"</perch:if><perch:if exists="ancestor_page"> class="ancestor"</perch:if>>
            <a href="<perch:pages id="pagePath" />#main-content"><perch:pages id="pageNavText" /></a>   
            <perch:pages id="subitems" encode="false" />
        </li>
<perch:after>
    </ul>
</perch:after>

Perch Content with Forms

By Philip Gwynne

Did you know you can use forms with , so you can pull in specific page content into your form. I’ve done this a few times now and it’s very effective allowing you to use one form for multiple pages/content.

A good example of this, you can see here on a website I created for Careline Lifestyles – all the care home pages on the site use the same contact form, which is pre-populated with the care home’s name, and the specific email address for that care home (using <perch:else> to input a fallback email address for homes without one yet). The care home names and email addresses are hidden from the front-end using in the form, so they only appear in the form results.


We’re going to try to publish lists of tips and tricks fairly regularly. If there’s something you do regular which you think isn’t part of the standard Perch workflow, or if you discover something that makes your life as a percher easier, try and summarise it in no more than 200 words and then send an email to [email protected].


Leave a comment