Young Hahn Proposes A Rule-Based Drupal Theme Layer

Bevan Rudge

on

March 12, 2009

Young Hahn Proposes A Rule-Based Drupal Theme Layer

While there were many great presentations at DrupalCon DC, Young Hahn's Limitations of the Drupal Theme Layer was the only one that blew me away. Most of the session attendees and readers of the related blog post seem to miss his main point; a proposal for a rule-based theme layer. Rule-based theming versus-command based theming is difficult to understand – possibly more so if you are already familiar with Drupal's current theme layer. One way to understand it better might be to think of it as a language & system that would allow you to use selector, perhaps like a CSS selector, to define the Drupal objects which some theme modifications are applied to. For example, something along the lines of
node.article title {
  <h2><span class="title-inner">$title</span></h2>
}
might allow you to override the markup of titles of article nodes. This is not a great example since this code is not and probably never will be machine-interpretable. However it demonstrates the use of a rule-based selector applied it to Drupal objects to modify the rendered markup, instead of an element's style. This, I believe, illustrates the still-hypothetical theme layer Young Hahn proposes. Rule-based theming is somewhat achievable with XML+XSLT, though not in Drupal – yet. There is an argument that XSLT is too difficult for designers or themers to use. I agree with Hahn's argument that it reuses all the same concepts that these people know from HTML, CSS and Drupal themable hooks. There are no new concepts to learn, just how they're applied. Therefore should not be difficult to learn. Further, technology changes. If it didn't it would be technology. As web builders it's our responsibility to direct this change in some areas and keep up with it in others. Most importantly, the extravagant advantages of a rule based theme layer are clear, at least to me, and well documented on Hahn's blog post on the topic (Skip straight to "Historical interlude: Remember 1997?"). What to Drupal core developers think of this change? What do Drupal contrib module developers and Drupal website developers think? What about themers? Designers? Let's have a conversation.

Share it!

Thanks Bevan for blogging this and re-starting this discussion. For those interested, I've posted the XSLT demonstration online, and you can download the source if you're interested in tinkering: http://is.gd/nfbG Keep an eye on the DS blog for a DCDC recap at some point with all of our slides, videos, etc. I have to agree that XML/XSLT is not necessarily the ideal implementation -- while it's very powerful the points that have been raised about barriers to entry are important to take into account. That said, I think it's important to recognize that Drupal's current way of handling template files puts far too much control in the hands of the module developer. The suggestions system used by phptemplate, for example, puts the novice themer at the mercy of what usage patterns the module developer thought would make sense. Ideally the theme layer would have control of the rules, not the modules. For the time being I think the most concrete next steps are to continue pushing more of the Drupal theme layer into structured arrays + drupal_render(). Once we are at a point where all of the page content is in a structured array without any (or very minimal) HTML already rendered, we'll be in a position to make much more interesting decisions (e.g. making the final output format of a Drupal page far more versatile and flexible).
i see the benefit, but it sure would move a lot of theming over to the programmer's plate. i spent all of last year working on a site using an xml/xslt cms (not my choice) and my theming guy never really got xslt, despite being well-versed in css and php, and having all sorts of xml/xslt resources available for learning. i had to set up all the templates for him. now, he doesn't completely grok drupal theming either, but at least he understands what the tpl files and associated preprocessor functions are up to when he reads them. in this other system, the xslt rules are elegant and it's sort of miraculous that they work the way they do, but they're incredibly cryptic -- it's not at all obvious what they're doing. and developing those rules was no fun at all.
Young Hahn's demonstration blew my mind. "rule based themeing" means "being able to say on the themeing level and saying I want that title to go to that region" without hacking at the output functions. He took Drupal planet and created like 6 DIFFERENT files with his demonstration. Anyway, it was incredible, I'm not sure what to do next, though...
Well, I just want to say that I _totally ignored_ this session because it had a horrible, non-specific, and non-constructive title. If the topic had been pitched as "Rules-based theming: A better way to support designing for Drupal", then it might have gotten my attention. /me ends rant.