Forum
Perch_content_custom 'page'
I have some [master pages] set up, and I want to use perch_content_custom to change the background of a section depending on it's folder.
Cattle Folder index.php - [course-category.php] (includes original perch_content which sets the background image for this category) cattle-course.php - [course.php] (uses perch_content_custom to get it's backgorund)
Sheep Folder exactly as above in cattle folder
However I have to refer to the 'page' starting at the root of the site. I have tried just putting in index.php as the page url which results in php not outputting anything. Is there a clever way to select index.php in the same folder as the current page?
Thanks
I don't really follow. Can you show us the code that isn't working, along with what result you're getting and what result you're hoping for?
Sure:
From course-category.php
And referring to that file is course-single.php
Currently where the '*' is I would like to refer to the index.php in the same folder as the current page.
Probably the easiest way is to get the current page path, explode it on a forward slash, drop the last item from the array, then append index.php and implode it on a forward slash again.
After looking around the internet thanks to your explanation I have found:
To get the current page path i found here:
https://stackoverflow.com/questions/6768793/get-the-full-url-in-php
Explode that:
https://board.phpbuilder.com/showthread.php?10380358-RESOLVED-explode-is-causing-problems
Take a look at the output using var_dump:
https://www.php.net/manual/en/function.var-dump.php
Pop the last item off, then append 'index.php':
https://www.php.net/manual/en/function.array-pop.php
https://stackoverflow.com/questions/6797641/php-how-to-add-to-end-of-array
Implode the array:
outputs: /courses/cattle/index.php
However, I can't get this next part to work:
Thanks, Adam
The reason is probably that the variable $url outputs /courses/cattle/index.php
however what I need to output is:
'/courses/cattle/index.php'
Manage to wrap the variable in quotes but perch_content_custom still doesn't work:
which outputs '/courses/cattle/index.php'
by the way course-image.html outputs a css background style. It works elsewhere in the site.
Perch doesn't care about the domain name - just the path from the root of the site. Don't use the domain or protocol.
That's what I am doing, aren't I?
It seems that giving perch_content_custom a straight url to the page works, however a variable with exactly the same content as the url will not work.
This works
This doesn't work
Make sure the path starts with a slash - the top instance shouldn't actually work!
Sorry, it actually does work - that was a typo.
$echourl = '/courses/cattle/index.php'
like I said, typing in the url in quotes works fine, putting in the $echourl variable doesn't.
Thanks for all your help so far.
I don't understand why you're adding the quotes to the string. The path doesn't contain quotes.
To clarify, when using perch_content_custom, if a url is referenced it is normally put in quotes as standard. When obtaining the url dynamically in a variable using this method, it outputs without quotes.
I still haven't managed to get this working.
Quotes are used to denote a string. If you have a string, you don't put quotes into it.