I'm within the template views-view--[view-name]--page.tpl and I want to fully style the fields within the templates. So I do var_dump($variables) and within this I can see all my nodes seem to be there, but there so deep within the structure it's impossible to see where exactly, plus this can't be the correct way to loop around it as I'd have a crazy long query!

So how do I simply loop around the view in the template I mentioned and get lets say the title and the body for the nodes in my view?

  • You can check how to render different parts of your view by looking at the default templates from the views module located under sites/all/modules/views/theme/. For instance if you where using views-view.tpl.php you would can print all nodes using print $rows;. You can then create another template views-view-fields--[view-name]--page.tpl.php to render all fields for a single node. Nov 13, 2015 at 16:19
  • Yes, that's where I started but print $rows just seems to print the block out in the style within drupal dictates. I want to surround it with my own bootstrap html so would like to pick the fields, html and css from within a template file
    – karl
    Nov 13, 2015 at 16:23
  • On the edit screen for your view you can also check the template suggestions by clicking advanced > theme information. You should be able to add markup for a single field in the view by using the views-view-field.tpl.php template Nov 13, 2015 at 16:26

2 Answers 2


Use views-view-fields--.tpl.php and render the field with your custom markup

For example:

<div class="product-item">
    <div class="row clearfix">
      <div class="product-image"><?php print $fields['field_images']->content; ?></div>
    <div class="row clearfix text-center">
      <div class="product-attributes"><?php print $fields['title']->content; ?></div>
    <div class="row clearfix text-center">
      <div class="product-attributes"><?php print $fields['title_1']->content; ?></div>
    <div class="row clearfix  text-center">
      <div class="product-attributes price"><?php print $fields['another_field']->content; ?></div>
  • Hi, thanks so to then embed this on the page within nodes template? I was using print views_embed_view('outputs','page'); but I don't think that would work for this
    – karl
    Nov 13, 2015 at 16:29
  • this will theme your view markup. So you can render your views as a block on a page or as a separate page
    – Shabir A.
    Nov 13, 2015 at 16:31
  • Just to follow up on @Shabir, don't embed views in a template. Use a block or other method like preprocess hooks.
    – cleaver
    Nov 13, 2015 at 16:49
  • ok cool think I'm getting my head around views now! So is there no way to get the field HTML. Basically what I want to do is attach some bootstrap button styling to a link to the node. I guess I could target it with js, but that seems a terrible idea!
    – karl
    Nov 16, 2015 at 10:31

I noticed I never explained how I solved this, for anyone who comes across this. The best way I found of doing this was if you go into the view, under fields select the field you want to change and then choose rewrite results and then select 'Rewrite the output of this field'. You can see what tokens you can use by clicking 'replacement patterns'. If you want to mix and match different fields you select 'exclude from display' on each field but the bottom one in the list which will then make it available as a token within the last field on the list. Simples!

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.