2

Here's what I am trying to do:

I need to have a way to display only the content in a node without any of the Drupal adornment. All I want is the styles to be inserted, and the content itself.

The reason I am doing this is I am setting up a portfolio web site that contains examples of work. Each clip will be displayed in a lightbox2 popup. A lot of the clips were authored in Drupal.

I don't want the site title, menus, and all of that garbage to show inside the lightbox. Just the content.

I did the following, which seems to be a non core files hacking way of doing things:

I created a new content type, called "barepage". I copied some content into barepage.

I created a new content specific template file for barepage: node-barepage.tpl.php.

Just for testing, here is what is inside this file (I commented out the actual content):

<div id="node-<?php print $node->nid; ?>" class="<?php print $classes; ?> clearfix">

   <?php if (!$page): ?><div class="list-node"><?php endif; ?>



  <div class="content">
   <?php /* print $content; */ ?>
  </div>

  <?php   if (!$page): ?></div><?php endif; ?>

</div> <!-- /.node -->

All of the standard Drupal stuff displays: the page header, the primary navigation links, the node title inside the page, and the page footer. But as expected, the content is empty.

of course, if I uncomment $content, the page displays like a standard "Page" content type.

What in the heck do I override to eliminate all of this stuff and just display the content? I'm trying to avoid hacking the template's core files or the Drupal core.

This is with Drupal 6.2, and the Zen theme with the CTI_Flex subtheme.

5

Main layout of a page is done in the page.tpl.php file. You have to override that templates for your bare pages in order to not output anything you don't want to see on the page. The correct way to override the used templates for a particular situation is to use suggestions.

From the Drupal 6 Template Suggestions, you can see that the suggestions to override this templates are summarized as page-[front|internal/path].tpl.php. So, out of the box, you only have to option to provide a bare template for either the front page of the site or all pages starting with a given path. There is no suggestion that allow you to override the page.tpl.php template for node pages of a specific content type.

But if you look at the page.tpl.php documentation, you see that the template has access to a $node object: The node object, if there is an automatically-loaded node associated with the page, and the node ID is the second argument in the page's path (e.g. node/12345 and node/12345/revisions, but not comment/reply/12345). Using this information, you can use the template preprocessing in your theme to add an additional page.tpl.php suggestion.

function THEME_preprocess_page(&$variables) {
  if (!empty($variables['node']) {
    $node =& $variables['node'];
    $op = arg(2);
    if (empty($op) || $op == 'view') {
      $variables['template_files'][] =  'page-'. str_replace('_', '-', $node->type);;
    }
  }
}

This should add the page-<content type>.tpl.php template suggestion for node pages. You can then create the page-barepage.tpl.php file with your simplified markup.

Keep in mind that this will not prevent Drupal from processing and rendering any blocks for the page, it will only prevent them from being outputted in the page.

0

The header, menu, footer etc are not in node.tpl.php but in page.tpl.php

To stop all those from displaying in the barepage content type, I believe you copy page.tpl.php and rename page-barepage.tpl.php.

Once that is done, you should be able to comment out all the php code for outputting those "undesireables"

4
  • Two things: I found (right after posting this) that the pages were being displayed not only from page.tpl.php but also node-barepage.tpl.php. page-barepage.tpl.php does not do anything - it's not seen (at least in my instance.) It appears that I can hack page.tpl.php to get what I need by detecting the "barepage" content type and acting on it, and I don't really need to use node-barepage.tpl.php. I didn't want to mix this garbage with the "standard" template PHP but the way things seem to work is giving me no choice.
    – Wannabe Tycoon
    Jun 17 '11 at 19:32
  • Allow me to suggest you get rid of your node-barepage.tpl.php and only use page-barepage.tpl.php. The former may be interferring with the later. And, you can certainly use php to dynamically check which content type is being looked at and then display or hide whatever features you require. But, that code obviously repeats a couple of times in the document and is a bit error prone. Instead, override page.tpl.php and then stop all the features you don't want to display.
    – sisko
    Jun 18 '11 at 1:30
  • Re: your suggestion, yes, that is exactly what I did. page-xxxx.tpl.php is not seen/executed. (I place some "test characters" in the HTML of such a file in order to see if it makes it way to the display.)
    – Wannabe Tycoon
    Jun 18 '11 at 3:25
  • @Wannabe page-barepage.tpl.php is used when you go to /barepage so you have to create this menu first, you can use drupal.org/project/empty_page.
    – tostinni
    Jun 18 '11 at 22:16
0

You should not have to hack core. See Drupal Template Suggestions for alternate naming conventions of page.tpl.php to override the default.

1
  • Covered that already. I said I'm on Drupal 6 and I followed the alternate naming conventions. The only applicable suggestion I saw was node-<type>.tpl.php.
    – Wannabe Tycoon
    Jun 18 '11 at 3:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy