node.tpl.php

How to create a block region for node.tpl.php

Update: appparently, today was the day to write about this. Nedjo Rogers submitted a handbook page that shows a different method of achieving the same end.

For the most part, Drupal 4.7's block system is underutilized. This is a shame; with the proper templating, drupal's block system can become a valuable workhorse. In this tutorial, you will learn:

  1. How to override default functions in the phptemplate.engine
  2. Create new regions to place blocks
  3. Pass a block region into node.tpl.php

By the end of this tutorial, you will have the ability to place blocks into node's like a so:

Quick and Clean CCK teasers Via PHPtemplate

If you are like me, you've been pulling your hair out trying to make teasers work in CCK. Well, as it so happens, I figured out a crazy simple phptemplate method of making CCK body fields act like any other node's body. Observe:

Template.php

<?phpfunction _phptemplate_variables($hook, $vars) {global $user;    switch ($hook) {        case 'node':            if ($vars['field_body'][0]['value']) {            /* Believe it or not, all you have to do is pass the field through             the existing node.module function node_teaser()! */                $vars['cck_teaser'] = node_teaser($vars['field_body'][0]['value'], $format = NULL);            }            break;    }    return $vars;}?>

Drop this in the appropriate node.tpl.php file:

<div class="content"> <?php //for teasersif ($page == 0) {    print $cck_teaser;} //for fullpageselse {    print $node->field_body[0]['value'];?>} ?></div>

On the Joys of Raising Free-Range node.tpl.php Links

Ah, chickens -- delicious chickens. Its a timeless truth, however, that not all chickens were born equal. And clearly, the best tasting chickens are those who've been allowed to feed, graze, and socialize on the open range.

Alas, this is not a white paper on the art of raising free-range chickens. Rather, its a tutorial on raising free-range node.tpl.php links such as "add new comment", "read more", or any other link which the multitudes of modules spew forth into that disgustingly generic $links variable. By the end of this tutorial you will no longer be limted by the $links variable. Instead, you will have the necessary code and knowledge to turn any link into a variable that you can place at any point in your node.tpl.php file.

Syndicate content