Extreme Drupal Theming with PHPtemplate

06.02.2006

Drupal's phptemplate is the most powerful, simple, and flexible templating/theming system on the planet*. Yet, it seems that the majority of drupal themers, (and wannabe drupal themers) are ignorant of its true power.

More disturbingly, vast numbers of people still insist that Joomla!, typo3, and wordpress's templating systems are easier, sexier, and slicker. These people are either loony, or wrong.

As an expert in PHPtemplate (isn't that scary), I've decidedits my duty to show the true power of PHPtemplate to world.

Consider these tutorials, a proper (and steadily growing) introduction to drupal's templating system.

*by all means, prove me wrong if you disagree.

Comments

buy wow gold cheap wow power

thanks.

thanks.

Hey, this looks great,

Hey, this looks great, but.... shouldn't it's power be shown in this site? I'm new to Drupal, and so far I like it. I guess time will tell if great templates start popping up everywhere, the true proof of a useful language such as English.

There are very old, and

There are very old, and obsolete.

Hey!..Thanks..

Thank you for he nice tutorial. Keep it up man
-Nish

Awesome

Good call amigo. I guess I'm the first to submit this to Stumble, so expect another hundred uniques a day (I think).

You're welcome.

*by all means, prove me wrong if you disagree.

Heehee Nick, the burden of proof is on YOU. And remember: extraordinary claims demand extraordinary proof ;-)

Vis a vis Wordpress

I'm a 100% total Drupal n00b and a major WordPress user, but I'm failing to see how PHPTemplate is different on a code-level from the WordPress theming system. That is to say; obviously, the way themes are applied to content is different (Drupal's content and publishing model is very different than WP's) and again, obviously, the APIs are distinct. But I'm not, thus far, finding major conceptual differences between WP's "template tags" and inlined PHP logic and PHPTemplate. Does anybody care to enlighten me?

Theming and taxonomy

I've been trying to get a question answered over on the Drupal forums (http://drupal.org/node/67684) but since it's a theming question I'm sure you know the anwser and it seems to fit in with your series here. Can taxonomy be used as a variable in template.php to control output such as whether or not an event date is output to the page? For example, if I were to event enable book pages, but I didn't want a date to be associated with particular book pages, at least not when the node is displayed to the person viewing the page. Or is there a cleaner way to handle that than taxonomy and template.php? Roger

A typo?

You state: So just to review your theme’s files should be: /themes/yourtheme/template.php /themes/yourtheme/user_login.php Shouldn't that be? So just to review your theme’s files should be: /themes/yourtheme/template.php /themes/yourtheme/user_login.tpl.php

Yep! Thanks for letting me

Yep! Thanks for letting me know.

Nice - some suggestions

Very nice tutorial, Nick! It's very refreshing to see that as your technical knowledge of Drupal has grown, and as you've started to write more "geeky" articles, your writing style has remained friendly and accessible. A noble goal for all of us Drupal bloggers, slash tutorial-writers. This tutorial does a great job of explaining that with the 4.7 forms API, you can override more than just theme_foo() functions in your theme. You can also theme any form, including one that doesn't have a theme_form_foo() function (i.e. you can override the theming of a form, even if there's no default theme function to be overridden for it). This is probably not obvious to many Drupal themers, especially those that are used to the limits of 4.6 theming. However, I have a few suggestions: 1. Themers can also output nodes directly in their theme with a call to node_view($node), or with a call to theme_node($node). This is preferable to directly printing the node title and body, unless you really need the extra flexibility. 2. node_view() wraps the title of the node in a call to check_plain(). So any method that bypasses this function (including calling theme_node(), or printing the title directly), should use check_plain() before printing the node title. Failing to do this will open a potential security hole in your site. 3. I'm not a big fan of hard-coding node IDs, even in a themable function. IMO, themers should instead use variable_get(), even if there's no front-end interface for changing the variable in question (you can at least develop one later if necessary).

wonderful!

+1 on the handbook suggestion. Well done!

Great

Great explanation! very useful! saving as pdf!

GREAT!

This was a really good tutorial. Thanks.

Thanks

Awesome tutorial! We need more like this :-)

Glad to serve, as always

Glad to serve, as always :-) Chapter 2 is already in the works. It will be an indepth look into theory, and best practices overriding themable, (and non-themable) functions. Basically, I feel I need to show example after example so that folks can begin to pick out the patterns. Or to put it differently, if I was following classical sonata structure, this post would be the first movement's exposition.

YEAH!!!

Yeah!!! Great work! Thanks for telling the world about the greatness of PHPtemplate!!!

Awesome.

Bravo. I hope you put this in the drupal.org handbook.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.