Custom themes for URLs called via AJAX (i.e. with Colorbox trigger).

Public

3 preprocess hooks, template.php (the purpose of this snippet is to display only the node content area, without additional page regions, like header, footer, sidebars, etc.)

Get raw version
php
  1. function MYTHEME_preprocess_html(&$vars) {
  2. if(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
  3. $vars['theme_hook_suggestions'][] = 'html__ajax';
  4. }
  5. }
  6.  
  7. function MYTHEME_preprocess_page(&$vars) {
  8. if(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
  9. $vars['theme_hook_suggestions'][] = 'page__ajax';
  10. }
  11. }
  12.  
  13. function MYTHEME_preprocess_node(&$vars) {
  14. if(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
  15. $vars['theme_hook_suggestions'][] = 'node__ajax';
  16. }
  17. }

Contents of the file: html--ajax.tpl.php

Get raw version
php
  1. <?php print $page; ?>

Contents of the file: page--ajax.tpl.php

Get raw version
php
  1. <div id="ajax-page" class="content">
  2. <?php print $messages; ?>
  3. <?php print render($page['content']); ?>
  4. </div>

Contents of the file: node--ajax.tpl.php

Get raw version
php
  1. <div id="ajax-node" class="<?php print $classes; ?> node">
  2. <h2><?php print $title; ?></h2>
  3. <?php
  4. hide($content['comments']);
  5. hide($content['links']);
  6. print render($content);
  7. ?>
  8. </div>