One thing i hate about views is this bunch of markup and nesting it uses to render the data on a page.

What i usually do to remedy this problem is iterate through the content variable and trim all tags so i can them display it as i wish. I know this kind of a dirty shortcut and i was wondering if there was a better way to do so.

Can' t views only output the raw data from the DB without adding all that markup to it ?

3 Answers 3


Are you using Views 6.x-3.x or 7.x-3.x? If so, you can do a ton of the grunt work of stripping out views' default markup by adjusting fields' 'Style settings'. If you're using an older version of Views, Semantic Views does just about the same thing. One gotcha: If you don't want the default wrapper around each field, you need to check the 'configure the field and label wrapper' option and set it to 'None' - that trips me up sometimes.

To adjust the other bits of markup around, for example, the entire view, or each row, you can copy the views template files (in the views/theme folder) into your theme's folder, and modify them to your heart's content.

The reason Views creates all this extraneous markup is that it is trying to be all things for everyone. I find, a lot of times, that it's easiest (and barely helps performance or page load times) to just go with the default markup, unless I'm trying to do some advanced theming. There's a class for just about everything!

On another note – if you're trying to return just some data, in a format like JSON or XML or something similar, you'll want to use a different display type for views besides one of the standard 'Unformatted fields' or 'list' types...

  • Thanks for your detailed answer, i think that would do the trick. I ll play around with it and let you know. One more thing though that would make this answer even more complete, is there a way to programatically grab a view result before it get populated to the view template?
    – silkAdmin
    Jul 7, 2011 at 10:58
  • See stackoverflow.com/questions/247991/… for more ideas... Don't have time to look into this more at this time :-( Jul 10, 2011 at 6:59

The easiest way to accomplish this is:

  1. Exclude the fields from displaying.
  2. Add a field and choose "REWRITE RESULTS" to rewrite it with the fields that you want (from replacement patterns). You can add markup around the tokens if you want.
  3. Uncheck "Provide default field wrapper elements" from show settings.
  • Thanks though i actually stoped using views as i found out that with just a little php/msql knowledge you get much cleanner and faster queries.
    – silkAdmin
    Sep 14, 2011 at 8:09

A combination of Views 3 and the Semantic Views module is usually enough for me.

Under extreme circumstances, when I want absolutely zero markup, e.g. to display a completely custom date, I create my own tiny template for the field in question (choosing the right file to create using the Theme Information part of the View). In your template, the default is print $output;, which is completely useless. For my date example, i replaced that with:

print my_pretty_date($row->{$field->aliases['field_date_value']},

That will let me run my custom date formatting function with dates in MySQL datetime format.

IMPORTANT: I don't know if the $row data are sanitized. It is hard to find out too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.