We are transitioning over to a new forum platform. Please post new issues there. Existing threads will be dealt with here unless you choose to move them over. Visit the new forum

Forum

Thread tagged as: Question, Problem, Configuration

Templates and Master Pages

Hello, I am new to Perch... very new. But having said that, I feel I'm a fast learner and quick to catch on.

I have made one very small site in Perch, where each of the 7 individual pages the site contained, had their very own individual PHP "template" file. I could retrospectively edit that "template" to add in a new Perch Content element and by front-end browsing to that template's URL, I could give it a refresh and then see the new Perch Content element appear within the page's Admin.

Now I'm trying to work on a larger site, where a whole group of pages will run off of a single "template", where the differing content added into the Perch Content elements will make Page1 different to Page2, despite both running off of one "template".

I was assuming that was where Perch Master Pages would come in and a Master Page would basically be a template that multiple Perch pages to be built from. But now I'm less sure. From what I'm seeing, a Master Page itself actually needs to have a Perch Page that the Master Page takes reference from.

So, I'm now at a point where I seem to have 2 templates... #1 inside the root directory of the Perch site, from which I have a Page within Admin, and then #2 inside Perch > Templates > Pages and template #2 is creating the Master Page... But then I need to setup the Master Page, so that it copies the regions from the page I made from template #1. Does that sound right? It seems excessively convoluted.

So, to state again, I'm after the simplest way to make a single Perch Template file, which can be used to create any number of pages within Perch, where the Perch Content elements within the template are filled with differing content page-to-page.

Cheers, m.

Martin Lowe

Martin Lowe 0 points

  • 1 year ago

I have watched this video - https://youtu.be/tcLxY1S25xY - which seems to corroborate the idea that I'm actually making:

  • (1) The initial template file for the initial About Us page.
  • (2) The actual About Us page inside Admin (using that initial template)
  • (3) The Master Page template file, which appears to need to be identical to the About Us template (except for the very first line of PHP code)
  • (4) The actual Master Page itself, within Admin, which has its Content Elements synced back to the original About Us page
  • (5) The ability then, to create any number of New Page(s) within Perch Admin... which takes its look from the Master Page... which takes its look from its own template file... which takes its look from the original About Us page... which takes its look from the very initial template file.

m.

I have attempted to follow/replicate the example(s) shown in the above video and when I create a new page, using the custom Master as my starting point, it does allow me to add in content for the Content Element inside the template(s)... But when I view the new page, the browser's front-end view seems to finish just before the custom content ought to be shown, and the rest of the page is missing.

For example (2) from my previous post = http://www.mjwebbassociates.com/temp/perch-test/perch-test-01.php - note the page ends with a fake 2009 copyright notice and has my custom content displayed in the middle of the second "article".

Now, the next two are both pages made using the Master Page = http://www.mjwebbassociates.com/temp/perch-test/perch-test-from-master-01.php & http://www.mjwebbassociates.com/perch-test-from-master-02.php - Both without any error message, failing to display both the custom content added directly into each page or any of the template's content beyond.

m.

Hussein Al Hammad

Hussein Al Hammad 105 points
Registered Developer

Hello Martin,

I was assuming that was where Perch Master Pages would come in and a Master Page would basically be a template that multiple Perch pages to be built from.

Yes, that's correct: https://docs.grabaperch.com/perch/pages-and-nav/pages/master-pages/

But now I'm less sure. From what I'm seeing, a Master Page itself actually needs to have a Perch Page that the Master Page takes reference from.

Regular Perch adds pages as files on the server. So even if you create the page from a Master Page, Perch has to create a file on the server for your page.

If you are working on a larger website, you can use Perch Runway. All the pages in Runway are created with Master Pages and it doesn't create a file for each page.

Hi Hussein,

Thanks for the reply.

Yes, that's correct: https://docs.grabaperch.com/perch/pages-and-nav/pages/master-pages/

I've seen that page, and to be honest, it's written in a style where you really need a decent grasp already, of how Perch works.

It would appear that the issue I was having was because I had set-up Perch inside the "back-end" of our own website and Perch was getting confused as to where it was creating files.

I have since setup a fresh install of Perch on a totally separate domain all of its own - and the Master Page test has worked exactly as it should. Now I can move on and actually start getting our Bootstrap theme into these templates.

Regular Perch adds pages as files on the server... All the pages in Runway are created with Master Pages and it doesn't create a file for each page.

If a project is built up to a point in regular Perch, with a series of pages created off of a small number of Master Pages, is it difficult then, to take that regular Perch site and convert it into a Runway site instead?

m.

Hi Martin

Welcome to Perch. As you've discovered, you shouldn't run a Perch site in a subfolder. It's just opening a whole can of worms. Especially with physical files.

If you are making a lot of pages then I would recommend looking at perch_content_create. This function assigns regions to templates as the page is created and saves a lot of faffing around when users are creating new pages from Master Pages.

It's really easy to transition existing pages to Runway. There are detailed instructions here. Runway is much easier to maintain and more flexible (with Collections and Routes). Runway does assume some basic knowledge of PHP. More so than vanilla Perch. But if I use it then anyone can ;)

Jon

Hussein Al Hammad

Hussein Al Hammad 105 points
Registered Developer

Yeah, like Jonathan stated; developing sites in subfolders is not recommended. From the docs:

We would suggest that you avoid previewing sites in a subfolder of the live site, and certainly never to actually develop on a live server in this way. By developing in a subfolder of the live site you are creating all of your pages a level up from the root of the site. To go live you then need to move everything up a level. In the case of Perch or any script that needs to know the path from root this is problematic and will leave you needing to fix the site on going live.

Your development environment should mimic the live environment as closely as possible – especially where the location of files is concerned.

Also see: https://allinthehead.com/retro/352/stop-building-sites-in-subfolders