Hey guys. Although I'm 95% certain making a file-based tpl file is more efficient than contemplate, due to the fact that it doesnt need the database, I would like someone to confirm... Is a tpl file more efficient than using contemplate?

Thanks.

Comments

WorldFallz’s picture

Yep-- but contemplate does have the ability to make your templates file based iirc.

m_i_c_h_a_e_l’s picture

I'm not quite clear on this one.

You said that tpl files are more efficient, but that contemplate has the ability to make templates file based.

That seems to be 1 benefit for each method.

Do you have an overall recommendation?

My feeling is, the fewer modules the better. But is that a good reason to choose one method over the other?

I'm now at the stage where I need to theme different content types, and this knowledge would be pretty helpful.

Thanks.

WorldFallz’s picture

When I first started with drupal, I did use the contemplate module. It was very helpful to have the initial code to start with because I was completely unfamiliar with the api at that time. Honestly, though, there's nothing in contemplate that can't be done with plain old theming. It's just a matter of convenience. And I supposed there's something to not using modules you don't actually need (decreased resource requirements)-- especially when there's a core way to do it. But if you're not having resource or performance problems, what difference does it make.

Theming different content types is as simple as copying node.tpl.php to node-content_type.tpl.php, clearing the cache (admin/settings/performance), and altering the file as desired.

m_i_c_h_a_e_l’s picture

Your comment on not needing to worry too much about using fewer modules is good information. I've always wondered about that.

Maybe I'm using the term "theming" wrong with regard to the tpl files. I assume we're both talking about cosmetic theming (i.e. fonts, backgrounds, etc).

I understand that you have to copy node.tpl to node-content_type_name.tpl.

I've studied the node.tpl file, but I'm not sure how to insert these elements. For example, if I want to change the background color of the content area, do I just insert an html background tag under <div class="inner">? I posted the text of my standard node.tpl file below.

And a second question: As I understand it, the node-content_type_name.tpl file must go in the same folder as the original node.tpl file. But whenever I update the theme, I delete the whole theme folder before extracting the new version. Wouldn't that delete the node-content_type_name.tpl file too?

Don't do my work for me, but please give me a little guidance on how to code this.

Thanks. You have always been a big help in my hour of need! :-)

<div id="node-<?php print $node->nid; ?>" class="node <?php print $node_classes; ?>">
  <div class="inner">
    <?php print $picture ?>

    <?php if ($page == 0): ?>
    <h2 class="title"><a href="<?php print $node_url ?>" title="<?php print $title ?>"><?php print $title ?></a></h2>
    <?php endif; ?>

    <?php if ($submitted): ?>
    <div class="meta">
      <span class="submitted"><?php print $submitted ?></span>
    </div>
    <?php endif; ?>

    <?php if ($node_top && !$teaser): ?>
    <div id="node-top" class="node-top row nested">
      <div id="node-top-inner" class="node-top-inner inner">
        <?php print $node_top; ?>
      </div><!-- /node-top-inner -->
    </div><!-- /node-top -->
    <?php endif; ?>

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

    <?php if ($terms): ?>
    <div class="terms">
      <?php print $terms; ?>
    </div>
    <?php endif;?>

    <?php if ($links): ?>
    <div class="links">
      <?php print $links; ?>
    </div>
    <?php endif; ?>
  </div><!-- /inner -->

  <?php if ($node_bottom && !$teaser): ?>
  <div id="node-bottom" class="node-bottom row nested">
    <div id="node-bottom-inner" class="node-bottom-inner inner">
      <?php print $node_bottom; ?>
    </div><!-- /node-bottom-inner -->
  </div><!-- /node-bottom -->
  <?php endif; ?>
</div><!-- /node-<?php print $node->nid; ?> -->
WorldFallz’s picture

first, I could be wrong, but I understand theming to include controlling the output html as well as styling with css. css only changes are usually referred to as styling.

second, yes, if you modify the theme directly you'll need to be careful to preserve your changes. The easiest way to do this is simply use the downloaded theme as a 'parent' and put all of your changes in a subtheme of it and make your changes there. note, even though you're using a subtheme, you'll still need a copy of the original node.tpl.php file in the same directory as your type specific ones.

And finally, you should be able to change the bg color of your content type with just css. You don't say which theme or content type you want to style, but if you examine the source, you should be able to identify a content type specific class on the main node div. then all you need to do is add the following css to your subtheme:

div.node-contenttype div.content {
  background-color: navy;
}
m_i_c_h_a_e_l’s picture

You were a big help.

I learn a little more each time I have to solve a problem!

WorldFallz’s picture

excellent! that's the idea ;-)

niccottrell’s picture

Another reason to use the node-xx.tpl.php rather than contemplate is that it makes upgrading or retheming a site easier. We are currently relaunching a site and have started with a new theme, which is only available to admin users in Drupal. We are adding translations and a few new fields to some content types, but want to keep the current site running. By having this node-xxx.tpl.php in the theme folder is lets us chance the layout and logic on the rendering of this content type without affecting the current live site at all!