Extreme Drupal Theming with PHPtemplate

Jun 1, 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 decided its 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.

Mon, 2007-08-06 04:26
By Nishanthe (not verified)

Hey!..Thanks..

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

Sun, 2007-07-29 02:07

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.

Tue, 2007-01-09 19:47
By a passing drifter (not verified)

*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 ;-)

Thu, 2006-07-20 05:56
By David Eads (not verified)

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?
Fri, 2006-06-09 01:30
By Roger (not verified)

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
Sat, 2006-06-03 21:58
By a passing drifter (not verified)

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
Sat, 2006-06-03 22:58

Yep! Thanks for letting me

Yep! Thanks for letting me know.
Sat, 2006-06-03 04:18
By Jeremy Epstein (not verified)

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).
Fri, 2006-06-02 17:09
By Laura (not verified)

wonderful!

+1 on the handbook suggestion. Well done!
Fri, 2006-06-02 15:39
By a passing drifter (not verified)

Great

Great explanation! very useful! saving as pdf!
Fri, 2006-06-02 11:35
By coreb (not verified)

GREAT!

This was a really good tutorial. Thanks.
Fri, 2006-06-02 11:24
By introfini (not verified)

Thanks

Awesome tutorial! We need more like this :-)
Fri, 2006-06-02 12:55

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.
Fri, 2006-06-02 07:35
By Steve (not verified)

YEAH!!!

Yeah!!! Great work! Thanks for telling the world about the greatness of PHPtemplate!!!
Fri, 2006-06-02 06:47
By merlinofchaos (not verified)

Awesome.

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

Post new comment

Please solve the math problem above and type in the result. e.g. for 1+1, type 2
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><p><h1><h2><h3><h4><h5><h6><code><cite><blockquote><img>
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Web and e-mail addresses are automatically converted into links.
  • Lines and paragraphs break automatically.
More information about formatting options