Why is drupal theming so difficult? Any tips for simplifying it or learning it faster?
Asked Answered
P

6

5

I've been coding in PHP for 4 years and even I find it so convoluted and hard to grasp. I have no idea how they expect designers to manage theming.

I know basic theming, theming with tpl files, views templates, contemplate templates etc. However I get lost whenever I enter the template.php file.

I needed to theme a node input form for a custom content type. I wracked my brain over it with like 7-9 tutorials and it's still not coming together. I understand why module building can be complicated - because most people who work with modules are developers anyway.

However, when even a developer can't understand theming, it's definitely over-engineered!

Maybe it's my fault, maybe I didn't learn Drupal properly. In that case, is there a step-by-step system to becoming a Drupal guru?

Phile answered 14/9, 2010 at 4:23 Comment(5)
I can understand your fury on the theming. But that really is no reason to insult people who spent parts of their lives developing this code. Please be a little more constructive, and avoid namecalling. -1 for that.Daimon
Thanks for pointing that out, I wanted to initiate a discussion on frustrations of Drupal theming and how to learn and develop Drupal themes quickly and painlessly - not just rant about it :p I've removed the offending line.Phile
Stack Overflow is not for extended discussion. If you have a specific, pointed question to ask, you're in the right place. Otherwise, I'd suggest a blog might be a great outlet to vent your frustrations.Frodi
General discussion, like "a set of tips" are okay too, but then the question should be marked as "community wiki" because there is no one single correct answer.Donniedonnish
-1: I actually agree with you, but this is not the place to post a general rant.Systematize
M
11

Theme is really not that difficult, if you only know basic php. You have 3 ways of altering the markup, the css and js, you should be able to handle.

  • Template files. By creating a template file in your theming and naming it correctly, it will take precedence over other template files, and you can thus create custom markup for views, nodes etc. By creating a template for a noce type, you can do stuff like printing out the cck fields in any other instead of using $content. All you need is on the node object.

  • Preprocess functions, which are placed in your theme, will give you the possibility to add or alter variables that will be used in your template. You name the functions like hooks: yourtheme_page for the page template yourtheme_node for the node template etc. Here you can create some custom logic, or modifications, to help make your templates more clean and just handle the printing of the variables.

  • Theme functions. You can overwrite theme functions to alter the markup that's used. You only need to create a function called yourtheme_[theme_function_name]. You don't need to understand much php to do this. Often, you can just copy the original theme function, and make a few alterations in it to get the markup you want.

With the above you can do 90-95% of what you need. Forms are a bit special since you in Drupal 6 can't alter them (easily) in your theme. Instead what you want is to create a small module and use hook_form_alter, which allows you to modify the form, text used on buttons etc. This is changed in Drupal 7, which will be even easier to theme.

So it really isn't all that complicated, just use the 3 basic tools described above. The tricky part can be to name your functions and templates, but devel themer can help you with that. Another tool you use is devel which can assist you in printing out variables so you can inspect them and see what you have available, fx CCK fields on the node.

Maracaibo answered 14/9, 2010 at 7:8 Comment(0)
S
6

Maybe you should get a copy of Front End Drupal.

In my opinion, Drupal theming is not difficult once you wrap your head around the concepts like templates, overrides, .info files and preprocess functions. Those things are not directly related to php skills, it's all about understanding the system.

It's interesting to see that you're a themer, yet you only talk about php, not CSS and HTML. In my experience, a lot of theming tasks can be accomplished with CSS, without even touching php.

Finally, I don't know if you are using a base/starter theme (like Zen or Genesis) already. I recommend using a base theme and realizing your own design as a sub theme.

Shoop answered 14/9, 2010 at 7:18 Comment(0)
B
6

Most people get an 'ahah!' moment when themeing suddenly starts to make sense.

I'd argue that this is probably tougher for experienced PHP developers, since you have to get past a lot of concepts that don't make sense in vanilla PHP ("the function is magically called at the appropriate time ... because of how it's named?!")

@googletorp's answers is pretty comprehensive, so I'll just add some practical tips that helped me along:

1) Try building a module that implements it's own themeable output and simple hooks. Hooks and theme functions make a lot more sense when you see how modules are actually calling them and using them.

2) Make liberal use of the devel module, especially the Theme Registry menu (note how it changes when you add a new theme function), the 'Render' tab, and the dpm() and dvm() functions

3) Buy a old-tyme dead-tree book on Drupal themeing. The online docs are really outstanding if you already know what you're doing, but can be extremely confusing if you're not sure what you're looking for.

4) Empty your cup. At the theme level, PHP is really just for simple logic and syntax -- almost everything of substance is getting handled by Drupal API functions. Try to think like a Drupal developer and not a PHP developer (i.e. don't assume you know how to do something just because you built a vanilla PHP site that does the same thing) and you'll have an easier time.

Keep with it! The theme system is actually really easy to use once you've figured it out.

Biskra answered 14/9, 2010 at 10:38 Comment(1)
I'm choosing this because it's the closest answer to my question(s): 1. Why is it difficult? 2. How to simplify/learn it faster?Phile
D
3

to answer your question on why it is so hard:

Drupal themes may seem overwhelming, due to the sheer amount of possibilities, see @googletorps answer for a good overview. Having "many ways to do one thing" brings power: power users can choose the best of all possibilities. But it also brings complexity: new users don't get a good lead, because there is no "you should do it this way. fullstop."

Alongside that amount of ways to get stuff done, there is the problem of nesting. Drupal has a concept of very deeply nested items. To take a random, yet simple example:

username<menuitem<menuitem<menuitem<menu<block<region<page. 

Will render a menu-item, containing a username in a three level deep menu-item in a sidebar-block. Where most templating-environments have concepts of a page, containing several "contents" that, at most, might contain some partials. the nesting is at most three levels deep. And each level has a clear, distinct area of expertise. Drupal does not have that: the nesting is fairly arbitrary. And each nested item is no different from its parents. This, again, offers power-users a great concept and power to work with, but is hard to grok for new developers/designers.

Lastly, another reason why it is hard to learn, is that the Drupal online documentation is more a wiki then a read-from-begin-to-end manual. There are great books that fill htat gap, you will have to buy them, though.

Daimon answered 14/9, 2010 at 8:14 Comment(0)
Y
1

If you haven't seen it already, this is a great presentation on why Drupal 6 theming is difficult and how it is improved in Drupal 7. There is hope! The video made more sense to me a second time watching after more experience theming. http://sf2010.drupal.org/conference/sessions/design-and-theming-whats-new-drupal-7

Yuletide answered 14/9, 2010 at 12:14 Comment(0)
D
1

One of the biggest tricks is to override something that is normal rendered with a theme function into a template. This gives you much more control over the markup, and also lets you use the preprocess functions to manipulate the variables before handing it over to the template.

This is a huge boon to theming forms. See a short video that explains it better than I could here: http://drupaldojo.com/session/fine-tuning-ui-theming-forms-drupal-60

Daley answered 17/9, 2010 at 5:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.