Forum

Thread tagged as: Question, Problem

Using php include on a Perch page, to link another page containing perch content

Hi all,

Forgive the long winded title. Basically I've been tasked with editing a site that was built by a previous employee, and the setup is that the navigation, footer, sidebar etc... are all in separate php files so that you can use PHP include to bring the same footer into all pages etc...

The problem I have, is that if you were to add a Perch tag into one of these included pages, the only way to have them show up in the perch backend, is to ensure you have a link to the perch/runtime.php. Which works fine to get in and add your content.

HOWEVER! As I'm sure you've already realised, this means that both the main page (say index.php) and it's included footer.php will both make reference to perch/runtime.php, which looks to break the page and as a result nothing loads.

Is there a way around this that doesn't involve hard coding the content into every single page? I am relatively new to Perch so forgive me if I'm going about it in the wrong way :)

Thanks!

Dave.

David Evans

David Evans 0 points

  • 7 years ago

Hey David,

Just read this and if you are adding php includes, the .php files you are calling do NOT have to have the Perch runtime on them.

A php include basically copys all the content from say include/footer.php and pastes it in index.php

Hope that helps.

Hi Chris,

This is what I thought, and as such, expected any calls to perch tags to work. Though I see this causing issues if I used it on something like a footer where I wanted to have the same thing in every file. This would definitely need to be hard coded.

I've just read about the use of layouts rather than include, and it looks like it might be more what I'm after. However I seem to be getting an error stating: Fatal error: Call to undefined function perch_layout() when I try to use it. The site is on perch version 1.8.4 though. Do you think this could be causing the issue? I can't seem to find what version of Perch layouts were introduced in to.

Hmmm, you could used 'shared regions' of you are wanting something that is in the footer to be editable.

Simply add in your perch tag as normal, load index.php and then in Perch, when you are choosing which template to use, click on 'share across all pages' - this shouldddd do the trick.

I would also reallllly recommend upgrading to the latest Perch too if possible.

Rachel Andrew

Rachel Andrew 394 points
Perch Support

David Evans said: I've just read about the use of layouts rather than include, and it looks like it might be more what I'm after. However I seem to be getting an error stating: Fatal error: Call to undefined function perch_layout() when I try to use it. The site is on perch version 1.8.4 though. Do you think this could be causing the issue? I can't seem to find what version of Perch layouts were introduced in to.

Layouts are in Perch 2. The Perch 1 docs can be found here: https://support.grabaperch.com/index.php?pg=kb

If it isn't in those docs then it's not available.

Ahh! Thanks for the clarification. Makes sense why it isn't working now :)