Forum
Ajax call to get content from a region
I have a few sub pages that have a content region called 'Description'. On the home page, I have a small widget that displays the those descriptions based on what the user selects. It works by just doing a post call to a php script below:
<?php include($_SERVER['DOCUMENT_ROOT'].'/perch/runtime.php');
$slug = $_POST['slug'];
echo $slug;
$content = perch_content_custom('Description', array(
'page' => $slug,
'skip-template' => true,
'return-html' => true
), true);
echo var_dump($content);
?>
At the moment I am just trying log the response to the console, but I get the error:
"The template <code></code> could not be found."
which, according to this thread should be sorted out by the "Description" argument.
The desired content is just a single paragraph.
Have you reduced it to a basic test case?
What result do you get?
Pretty much the same error:
The NULL appears when I use var_dump. Echoing just the variable gives the same error as before.
The same widget also gets a list of the navigation items on the page, which works fine:
Could that be interfering?
It sounds like that region doesn't exist. If you turn on debug, what does it output?
I've placed the ~~~ PerchUtil::output_debug(); ~~~ debugger in a few spots on the page, and in the script that Ajax calls, but I can't get it do to return anything at all.
This is on the bottom of the admin page with the description region:
The region is the only thing on the page with any content. It is getting called from a page template, does that make a difference? The pages these descriptions on are templates that have been used to make new pages from the dashboard.
Call the script directly - you need to reduce this to a basic case, eliminating all JavaScript.
This is the debug from the script:
I tried a region with a different name, and all kinds of different page paths and still nothing. Those values that are in the debig are the correct values that I want. Both the page and the regions are definitely there, and I've hardcoded to values right in there.
The page
/courses/technology
does not have a region calledDescription
Are you sure the page isn't
/courses/technology.php
or/courses/technology/index.php
?EUREKA!
Adding
/index.php
has found what I need! I was using the same url structure as my navigation templates, and my .htaccess is removing all php extensions. Thank you for your help!