Drupal 7 Overridding HTML Output Based on URL Conditions

Drupal 7 supports downloadable sitewide themes. Sometimes we want a specific site path to exclude many regions of a site and present only the page content. Or for instance if a remote site is fetching the page contents and embedding it in their site, we would not want to show all the banners, sidebars etc on the page. In the below example a client website can request any page of the website with an additional url parameter &remoteembed and the page output will be stripped of banners, header, footer and sidebars for remote embedding into another website.

We can use the Drupal Theme API to modify page output to show only page content we want. We will utilize an override to template_preprocess_html() and provide a theme suggestion to inform drupal of an additional HTML template for a pages of a given content type and a custom body class to provide a mechanism to target these pages via CSS if need be. We also provide a custom hook_preprocess_page() to strip nested content within our $page content.

Author Spotlight

David Gurba

I am a web programmer currently employed at UCSB. I have been developing web applications professionally for 8+ years now. For the last 5 years I’ve been actively developing websites primarily in PHP using Drupal. I have experience using LAMP and developing data driven websites for clients in aviation, higher education and e-commerce. If you’d like to contact me I can be reached at david.gurba@arvixe.com