After seeing so many people complain about Drupal's theme engine and it's inflexibility, I decided to try for myself and convert an existing Nucleus theme to Drupal. I used bluemarine (phptemplate version) as a baseline.

http://www.lassiter91.com/

Here's my experience:

1. Getting the basics done is pretty simple. It's easy to setup a container and set the global look and feel.

2. The problem is when I tried to theme items like navigation. I found that even ul and li styles are defined in a way not easy to change.

3. The biggest issues is when I tried to split out things like "date posted," "posted by," and "read more" (which I mentioned elsewhere.

4. I figured I would have to heavily edit the style.css but it turns out I had to edit page.tpl.php, node.tpl.php, block.tpl.php, and comment.tpl.php. That's pretty much each major theme file.

My Observations
I appreciate how simple it is to make global changes to the theme quickly but I'm left wondering why changing details deeply buried. I now see why most Drupal sites can be identified by the links line: print $links. I feel this should be split into separate functions: from a user perspective, comments and read more have nothing to do with one another. I would also like to see print $submitted opened up to allow for customized dates (like in the Stanch theme) and separating username from date posted. Again, it's not necessarily desirable to group these two items together.

I'm going to continue to modify this theme until I get it exactly like the Stanch theme. Unfortunately, by the time I'm done it looks like I will have modified several core files including some in the /modules and /includes directory. Once I'm finished I'll post the final theme if anyone is interested (with the caveat that once you upgrade from 4.6 it won't work anymore).

- Matthew

Comments

eaton’s picture

... including a custom template.php file in your theme. That allows you to implement functions that override default behaviors lik the construction of the links array, etc.

Also, your node.tpl.php file has access to all the details of that node's data. $submitted is just a convenience variable that te PHPTemplate engine provides. If you want to build a custom info line for the node, variables like $node->created and so on are there for you to use. :)

--
Jeff Eaton | I heart Drupal.

--
Eaton — Partner at Autogram

heine’s picture

don't hack core files. You'll break your installation in the future.

I'm currently converting the theme of my site to a 4.7 PHPTemplate. Currently the theme is pure php. I find phptemplate to be very easy and flexible; to whomever wrote it: great job. I hope I can add my theme (a little spiced up) to drupal.org before 4.7 is released.

After reading your post I decided to see what other vars were available. $node->links is an array with all the links for the current node (add new comment, read more). The index for read more is not garanteed however; it depends on the amount of links. I'd like them more like array['read more'] = 'the link';

This is the ugly hack in node.tpl.php I've come up with:

<?php
    foreach($node->links as $item){
      $split = preg_split("/(>|<\/a>)/", $item, 0, PREG_SPLIT_NO_EMPTY);  
      $my_links[$split[1]] = $item;
    }  
?>

Then when I'm at a point I want to print the read more link:

$rm = t('read more');
if ( isset($my_links[$rm])) {
  print $my_links[$rm]; 
  unset($my_links[$rm]); // delete so it won't appear elsewhere
}

The rest of the links can be printed with a foreach or:

  print implode($my_links, '|'); 

(You can combine this with http://drupal.org/node/16383)

CAVEAT: I've written this in the middle of the night (nearly 3am) and haven't thought of all the possible consequences nor tested it completely. One possible problem is that the remaining links are not always printed in the same order.
--
Tips for posting to the forums.
When your problem is solved, please post a follow-up to the thread you started.

heine’s picture

Better change the splitting to:

<?php
if (isset($node->links)){ 
    foreach($node->links as $item){
      $split = preg_split("/(<a.*>|<\/a>)/U", $item, 0, PREG_SPLIT_NO_EMPTY);
      $my_links[$split[0]] = $item;
    }
}
?>

This makes it a little bit more robust. Note the ungreedy pattern modifier. If ommitted the entire string $item is matched.

Also change the printing of the other links to

<?php
    if(isset($my_links)){
      print implode($my_links, ' | '); // note spaces around |
    }    
?>  

Otherwise you will get an error when my_links is completely empty.

--
Tips for posting to the forums.
When your problem is solved, please post a follow-up to the thread you started.

rareexample’s picture

Hi Heine,

Can I use this method to move other items in links such as "times read"...

I tried using

										<?php
$rm = t('Number of views');
if ( isset($my_links[$rm])) {
  print $my_links[$rm];
  unset($my_links[$rm]); // delete so it won't appear elsewhere
}
?>

But that didnt work, any suggestions?
Thanks in advance!
Ss

My php skills are well, not so good...

heine’s picture

In comment.tpl.php

<?php
if(isset($links)){
  $comment_links = explode(' | ', $links);  // note spaces around |
  foreach($comment_links as $item){
      $split = preg_split("/(<a.*>|<\/a>)/U", $item, 0, PREG_SPLIT_NO_EMPTY);
      $my_links[$split[0]] = $item;
  }
}
?>

This relies on no-one ever translating a link with a 'space|space' pattern.

Print the reply link:

<?php
  $rp = t('reply');
  if( isset($my_links[$rp])) {
    print $my_links[$rp]; 
    unset($my_links[$rp]); // delete from array
  }
?>

To print the rest of the links:

<?php
    if(isset($my_links)){
      print implode($my_links, ' | '); // note spaces around |
    }
?>

add markup where necessary...

--
Tips for posting to the forums.
When your problem is solved, please post a follow-up to the thread you started.

nautis’s picture

Heine,

You're the man! Thanks for looking into this. I will try your suggestions and post back this week. Thanks again!

- matthew | nautis.com

Marc Bijl’s picture

Hi,

Heines solutions used to work like a charm with previous versions of Drupal. However, now that I'm building a website with 5.1 it seems like things have changed... Does anyone know how the code can be changed so that it will work with 5.1 too?

Thanks!
Marc

___________________
discover new oceans
lose sight of the shore

jwilde’s picture

if (isset($node->links)){
   foreach($node->links as $key => $item){
     //$split = preg_split("/(<a.*>|<\/a>)/U", $item[1], PREG_SPLIT_NO_EMPTY);
     $my_links[$key] = l($item['title'], $item['href'], $item['attributes']);
   }
}
 $rm = t('print');
 if ( isset($my_links[$rm])) {
 print  $my_links[$rm];
 unset($my_links[$rm]); // delete so it won't appear elsewhere
 }
   if(isset($my_links)){
     print implode($my_links, ' | '); // note spaces around |
   }

jim

Christefano-oldaccount’s picture

More about this snippet can be found at http://drupal.org/node/21538#comment-81773

summit’s picture

SUbscribing for drupal 6, greetings, Martijn