CSS vs PHP

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
mattmm's picture

Looking for some feedback to what others fight most when developing a new site's theme. Do you spend a majority of time tweaking CSS or PHP with your new theme?

When we develop new sites, all of our theme is built via CSS. I know there are some that "theme" with PHP Hooks etc. My thoughts are there is a grey area to themeing. Meaning, some "theme the output/display of data/fields" and others affect the look and feel of the theme via css. Is there a wrong way or a right way?

Your feedback is welcome!

Comments

undoing defaults

Dublin Drupaller's picture

Undoing defaults is a big one for me. In other words, using the template.php to catch and spit out specific drupal output with a different structure and markup. A simple example might be modifying the structure & markup of primary links output or the search/login box/block output.

On that point, I've suggested (and hopefully persuaded) the Drupal eCommerce team to build their new ecommerce API for Drupal in such a way where the THEME functions are kept seperate from the modules.

In other words, the ec_cart.module (which controls the layout of the ecommerce cart pages) will look for a cart template file in the default theme folder, which contains all the necessary theme functions for the module...if there is one, it will pick it up and use it, if there isn't one, it will pick up the default that is in the module folder.

A very simple idea and I think it's the way theming functions should be handled in all Drupal modules.

The main reason is that a designer/themer doesn't require an indepth knowledge of php/mysql functions to tweak the markup output of a drupal module by fiddling around with template.php. All they have to do is copy the template file in the module folder to their default theme folder and modify it.

There maybe a very slight overhead in the module looking in the default theme folder etc. but it's negligible when you consider the time saving aspects for develpment and the amount of .inc files that drupal already uses.

Re: the "right way"....

I think the "right way" is CSS only, although the ability to modify the tpl.php files helps enormously when writing CSS for your sites.

If you can't achieve the design and layout you want by CSS and tpl.php files alone...the "right" way of theming output is to use theme functions overrides in your template.php file rather than modifying modules...despite the temptation where you know a one or two character change in a module will do the trick, compared to a few hours or more working out the correct syntax for overriding a specific function.

dub

"The main reason is that a

mattmm's picture

"The main reason is that a designer/themer doesn't require an indepth knowledge of php/mysql functions to tweak the markup output of a drupal module by fiddling around with template.php. All they have to do is copy the template file in the module folder to their default theme folder and modify it."

Nirvana!

theming Nirvana..

Dublin Drupaller's picture

I think it's as close to a theming 'nirvana' as you can get..

Upgrading may require some re-jigging of your modulename.themefunctions file modifications. But, under the current drupal approach - where theme functions are embedded in .module files - if there are theme function changes in the module, upgrading requires you to fiddle about with the template.php file anyway.

From a designers point of view...modifying a seperate modulename.themefunctions file in your default theme folder (as outlined above) is much much much faster than having to learn php (well beyond the basics) and digging around trying to find the correct syntax to implement the template.php function override.

Even with the best intentions, designers can lose the will to live trying to work out something simple like overriding the default drupal module output markup for just one element.

hopefully, the suggested approach is adopted for the new Drupal eCommerce API and there will be a working example to point to...leading to all Drupal modules structured the same way. I'm sure there are probably some hidden drawbacks, I haven't thought of, but, the fundamental benefits are so huge for designers and themers, I think it's worth trying.

dub

CSS, all the way

geerlingguy's picture

I know little PHP, so I stick almost exclusively to CSS, changing bits of PHP only when necessary.

A bit of both

derekwebb1's picture

Usually I have to do quite a bit of both. As Dublin Drupaller rightly pointed out, undoing defaults is a big part of it. Though, once I get the core php stuff done (the codebase / framework) done, I usually don't have to do much more php work unless serious changes => (additions / subtractions / restructuring) are needed.

Without modifying the underlying code, I can't add all sorts of extra markup that will be guaranteed to tick off all of those semantic web designers! Sometimes, that stuff is a real boon too if you have a complicated design in mind. I personally try to be as "semantic" as possible but I am sure I have room for improvement there.

I think it would be neat to see how far the limit could be pushed though on that front. I imagine that with a lot of work and a bit of luck, you may just be able to get a nice looking theme without changing any php. In that case I imagine that you would have to start with a theme that had a rich pattern to start with...

I do a lot of both, in

jeff1970's picture

I do a lot of both, in particular if I am using View, Panels and CCK. Overriding the default output of these modules is mandatory if you want to reduce the page-weight and code clutter to something the SEO consultant won't have a heart attack over.

Modding forms is another big one, hook_form_alter and a custom module is where I spend a lot of time for many sites.

CSS is obviously the main tool for styling elements and the amount of time is great, especially for very advanced designs. I'd say on a balance I spend a lot more time on the CSS simply because it demands it.