[support] Templating in Drupal 5.1 - the cleanest way to do it?

J-P Stacey jp.stacey at torchbox.com
Thu Apr 5 16:06:01 UTC 2007


Hi,

I'm fairly new to Drupal. I've downloaded and installed Drupal 5.1, and 
we've got it working with multiple sites and modules very quickly. A lot of 
things *just*work*, which is great.

One aspect I've found quite confusing is the principles behind templating (I 
can manage the PHP nitty-gritty reasonably well). There seems to be a number 
of different ways of doing templates - PHPTemplate, XTemplate, a .theme file 
- which I appreciate may be for historical reasons. I've also seen 
conflicting advice on the Drupal site for how to override default templates 
and functions.

Our Drupal themes would end up quite large owing to specific client 
requirements, so I really want to start as I mean to go on! So what's the 
best practice for templating?

A few examples of stuff I want to do might help illustrate the problems I've 
been having:

1. If I wanted to hook into the code that creates e.g. $sidebar_left, how 
would I do that? It seems to be created by theme('blocks' , 'left') in the 
phptemplate engine. Should I just discard $sidebar_left, or is there some 
hierarchy of function names that theme() calls? Can I put any such functions 
into some file in my theme directory and they'll always get recognized?

Should I call such functions e.g. theme_block_left, or 
phptemplate_block_left, or THEMENAME_block_left ? Or should I instead use 
.tpl.php files exclusively e.g. block-left.tpl.php?

2. For different node types, I just can't seem to get the system described 
at <http://drupal.org/node/104316> working properly. It works fine for the 
node-content sub-templates e.g. node-video.tpl.php will get called over 
node.tpl.php, but e.g. page-video-edit.tpl.php just doesn't get called.

Is there something I'm missing? Would this hack here 
<http://drupal.org/node/117491> be worth looking into?

3. A bit of a random one, but say I wanted to change the content of an admin 
page. We'd be using Drupal for very heterogeneous sites (so e.g. events 
nodes, news nodes, courses, content, press releases etc. etc.) so the 
"Create content" page would start to look very cluttered. Any way of 
overriding that at the theme level? Also, we could have many user roles, so 
we would want to change the look of the permissions pages too.

Many thanks in advance,

J-P

-- 
J-P Stacey
+44 (0)1608 811870
http://torchbox.com


More information about the support mailing list