Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I had a requirement where an outside server wanted to use content from a Drupal site. The Services module does some of that, but requires an XML or JSON RPC call. So, in addition to Services and a custom module that can write out files, I added the following to at the top of my theme, before the !DOCTYPE tag
<?php
// make me smart
// just return the part of the page the caller wants
$context = $_GET['context'];
switch ($context) {
case "content_only":
print $content;
return;
...
}
?>
The caller can hit my site with
http://example.com?context=content_only
and get just the HTML for the content section of the page. If no context is specified in the URL, the user gets the whole page. Depending on the theme you're using, this can work for menus, sidebars, regions, etc.
Comments
Clarification
This goes at the top of page.tpl.php. If you're using a theme that implements preprocess_page() in template.php, you can put $context = $_GET['context'] preprocess_page().