Welcome to my corner of the web. Here you'll find my ramblings about faith, church, drupal, Geeks and God (my podcast), and my other unrelated interests.

While you can subscribe to all posts here from the Subscribe link on the right, there are two other main feeds. There is the drupal and other technology feed along with the faith and church feed.

The Horror of Views Markup

Posted on: Thu, 2009-08-27 08:35 | By: matt | In:

bride-of-frankenstein.jpgEvery so often someone points to the markup generated by the Drupal Views modules and calls it ugly. This seems come up every so often in the forums, issue queues, blog posts, and on twitter. Most of the time this is where the conversation turns a bit ugly. Since this conversation has been had many times the people who are involved are a bit tired of explaining what's going on to someone new and to many Views is their baby and it was just called ugly. So, let me take a shot at explaining why Views markup is the way it is, why that's good for some, and what you can do about it if you don't like it.

The Deal With Views Markup

The markup from Views has to be very flexible out of the box. It's going to be used by a lot of people to do a lot of different things. So, the markup provides spans, divs, and classes for almost every case you'd want to style. If you are someone who lives in CSS and loves classes and separation of everything it's there for you. There is a certain group of designers that want this and they have been vocal and are, for the most part, happy with the markup.

Can't Make Everyone Happy

As the saying goes, you can't make everyone happy all the time. Having lots of spans, divs, classes and other forms of markup is directly opposed to small concise markup others love. You can't have both out of the box and what Views picked is actually easier for new people to pick up.

In Drupal to alter the output you need to know how the theming system works and how to override the default markup. Since Views provides lots of markup many people can learn to style the output without needing to know how to alter the markup output of views. It saves them from a layer of complexity.

Having Markup Your Way

If you are a markup purist and want to change the markup output by Views it's there for you to change. Views uses the templating system provided by Drupal and has a display plugin system of it's own. With the templating system you can override all of the markup provided by Views and replace it with your own. It's almost as simple as copying the Views template files into your theme and altering or replacing them.

Drupalcon Paris

As Morten does at the Drupalcons he attends, in Paris, there will be a session about overriding the default markup in Drupal to replace it with what you want. If you're not going to make it to Paris you can wait for the video from his session to be published or check out the video of his session from Drupalcon DC.

Comments

#1 As someone that "lives CSS" I

As someone that "lives CSS" I thought I should point out that good markup is more important than a host of classes and ids that can be hooked into.

Proper, semantically correct HTML elements are the building block for a robust CSS styled web page. The IDs come next and finally classes.

The problem I see with a lot of HTML produced by back end developers is that they believe that sticking classes and IDs on everything makes their HTML somehow "good". If anything, it makes it worse.

#2 Some Clarification

I should have been a little more clear when I pointed out someone who "lives CSS". There is a certain group of front end developers who like lots of classes, spans, divs, ids, and other markup for them to style with CSS. They like all this stuff. They prefer it this way.

There are others who like concise clean markup. That's a different breed from front end developer. Their styles are at odds with each other. Views can't cater to both of them.

Instead Views provides a good generic stating point where someone can come in with CSS and style for many different use cases. As Jeff Eaton pointed out on twitter, this is a compromise that's come from years of work.

I personally would challenge someone to create something better that's as flexible to style out of the box. I have yet to see anyone try this. It's easy to talk about and not nearly as easy to create.

#3 As someone who practically

As someone who practically *is* CSS, I infinitely prefer the hooks method if it's coming from someone who's relatively inexperienced with markup. Maybe the original developer and I disagree on semantics (assuming they know anothing about them), but a horde of classes and IDs (assuming they make some sense, at least) ensures that I will be able to make it presentable.

Generally speaking, providing classes for anything of significance is a best practice in frontent development.

#4 Facts and Intentions

There are two sides of this argument I think - one about facts and one about intentions

Fact: Views markup allows lots of people (even those not skilled in CSS) do lots of things relatively easily. There are so many classes in there you tend to manage to change what you want

Fact: The markup is messy

Fact: You could still be flexible with cleaner markup

The above are not the problems I think. I think where the animosity springs up is when someone craps on Views markup period. Because then intentions kick in.

Ok so Views markup could be better. What are YOU going to do about it.

And that's the phrase that contains all the anger. If someone says that Views markup is crap and here is a patch that makes it semantically beautiful and delicious AND here is a lovely 2 page document that explain to everyone how to use it then no-one could complain.

Now, it would be a better world if criticism could be taken just for it is - especially when it comes from people that know what they are talking about - but calm reflection is not always the way of the interwebs and open source unfortunately.

Finally, and I fall in this trap often including today, one should not go on about how you can change everything yourself anyway. If we want Drupal to become better then we need to sit down with these pesky designer types that go on about beauty and semantics and figure it out once and for all...

#5 Are Your Volunteering?

Ronald, are you volunteering to organize the designer types to come up with better still flexible markup for Views? It would be great if you did. You'd make a lot of friends if you could build that bridge and come up with a better system.

At this point no one has. I know I don't have the time for it. Maybe a sprint at a future drupalcon. A markup sprint.

#6 If someone says that Views

If someone says that Views markup is crap and here is a patch that makes it semantically beautiful and delicious AND here is a lovely 2 page document that explain to everyone how to use it then no-one could complain.

Oh, but that wouldn't stop them. You see, every front end developer has a different definition of what makes for good semantic markup. Some want one class, some (see Nicole Sullivan's OOCSS) want multiple classes. Some want a class on every element, in case they need it, some only want the classes necessary for the specific design they have in mind.

And if you gave front end developers full control over the HTML emitted by Views, they'd complain about having to code that, as well. (I speak from experience with That Other CMS in this case.)

The key comes from a line from an old episode of West Wing: "Decisions are made by those that show up." Those of you who show up, who contribute code to the project, should get together and decide what *you* think the right markup is, and (re)build it to those standards, and let the rest of the world who does nothing go ahead and whine about it, without worrying about what they think. You have a good pro (Mark Boulton) you can consult with, if you want an outside opinion.

Yes, it sounds harsh, but the bottom line is that no matter *how* you write it, some will hate it, and some will love it. So worry about satisfying the ones who are actually doing the work. You'll get farther with that.

#7 I have learned to like View markup

I really hated the verbose markup views and cck produce at first. I had trouble finding the right CSS selectors to use because there were so many to choose from. Yet, as my CSS skills have improved, I have grown to appreciate the fact that there plenty of CSS classes and IDs to hook into and I rarely need to theme views to get a an ID or class. Sure the markup is somewhat heavy but I question if this is really a big problem.

Since I keep hearing it is a problem, I wonder if there is a way to give Views a minimal markup mode in the next release. The idea is check a box and you get one wrapper div with an id or class and that's about it. If you choose a list, you get a ul and li tags and that's it. If you need anything else, you theme it to your liking.

Just a thought ...

#8 View style

You should be able to create a view style plugin for that. I haven't actually tried it but I can't think of any reason why it wouldn't work.

Michelle

#9 Round and round we go

This keeps coming up over and over and over again. And Mark Boulton is surprised that Earl and his supporters are fed up with it? This is open source. If you have a problem with something, fix it. Seriously. Insulting peoples' work isn't going to make it better. I keep hearing people say over and over that the HTML views makes is bad and claims that it could be better and still do everything for everyone. But these claims never include patches.

It's pretty simple:

1) Earl has done the best he can to make markup that works for the most people. He's worked very hard on views. If he could have made it better, he would have.

2) Insulting Views does nothing productive. It's not going to improve the module because of #1.

3) If Views' markup is going to improve, it needs to be fixed by one of those people who claim that it can be awesome markup and still work for everyone. Again, because of #1.

As a maintainer myself, though of a much less popular module, I've faced this as well on a smaller scale. Advanced Forum's markup isn't the greatest but it's the best I've been able to do. If someone comes along and tells me it sucks, I'm going to say "so fix it". It's not me being nasty or sensitive. It's a simple fact that I've done the best I can to get something that works for most people and insulting it is not going to make it magically any better.

Michelle

#10 Different Way To Handle It

I understand where Earl is coming from. He has invested a lot in Views and has tried to make it the best he can for the masses. In many ways I love the module and how it works myself. I, also, understand the frustration that can come from the markup discussions. There are a lot of compromises that have been made and you can't make everyone happy.

But, rather than telling someone off (even if politely) a better way is to invite them to create something better. I have yet to see that happen which is sad. If some of these people who are great with markup were invited to come up with something better I'd hope they can. This is a much better way.

#11 Inviting

Earl has asked for help in the past. Sometimes he gets it, like the folks who stepped up to help with the UI for Views 2. But all too often it's just him doing the best he can. If someone comes along who has taken the time to understand the issues involved and comes with a better way of doing the markup that will work for everyone or at least the 80% I'm sure he'd be happy to listen. If you come at him saying "this sucks, fix it" he's rightfully going to be upset.

Michelle

#12 Misunderstanding

It seems you are under the assumption my comment about the Views HTML was:

1) A slight on Earl's work.

2) A personal attack on Earl himself

It was neither of these things. I'm unaware of the history of the Views HTML arguments and discussions. That's not to say the HTML Views produces, by and large, is poorly executed. Now, that tweet that sparked all of this was venting. From venting and frustration comes considered approaches to improve things. That would be the natural next step - and actually it's already happening.

This whole 'this is open source, fix it' argument is actually completely mute in a hyper-aggressive, defensive environment.

#13 Views markup is good

I had a problem with views markup before, but for the person who fears coding, or has no desire to it meets any need you can foresee.

It appears verbose, but after using it a lot I realize it has been designed to be comprehensive enough to accommodate all possible requirements.

What would help would a UI that would allow users to choose the level of markup required for a particular view. But who is going to volunteer to code that, or create a module for it?

#14 theming on a different level

How many Drupal themes have these critics under their belt? I too used to dislike Views/Drupal HTML when I was a beginner. I thought I was a sitebuilder ninja who knew better, but frankly, I was just clueless. Content management systems are huge beasts and theming them requires skills and understanding on a whole different level.

The only issue that I had with Views recently was the use of divs instead of <h1>, <h2>, etc. tags around title fields. There was no way to overwrite those divs globally, so I went to the Views issue queue and got what I wanted. I posted the issue at 19:51 and by 21:28 it was fixed. So much for the un-responsive Views developer.

#15 Earl deserves a better audience.

For every article I have read on this issue I am yet to see someone who'll step up and actually add some valuable input rather than just comment. I am yet to see a better project than views in its own right.

Quote:
Having Markup Your Way
If you are a markup purist and want to change the markup output by Views it's there for you to change. Views uses the templating system provided by Drupal and has a display plugin system of it's own. With the templating system you can override all of the markup provided by Views and replace it with your own. It's almost as simple as copying the Views template files into your theme and altering or replacing them.

Need I say more. There is a way around it.

Earl is a hard working coder that deserves a bit more respect, without the personal attacks. Hours spent deserve credit and respect.

#16 Loads of Respect

First, Earl gets loads of respect. He gets it for much more than his work on Views. You can look at Panels, Drupal core, and other places to find his good work and he gets respect for it.

This post was not about the issues Earl has run into and it's sad to see that when the html for views comes up the discussion immediately turns towards defending Earl rather than addressing the html and looking to improve it. Earl doesn't need us to come to his defense. Earl can use us helping make Views, Drupal, and his other projects better.

Also, when you have a popular project people will criticize your popular work. Whether it's a movie, song, building, software program, or anything else. That is our culture and world. Views will always have critics and part of what they say may likely be true. The trick is to turn that criticism into something actionable or simply ignore it.