1

I created a block view and am having trouble controlling the out put. Theme developer tells me the candidate template file is views-view-fields.tpl.php that file doesn't look like any of the others I have worked on. I have found the only control I have over the output is through the view settings itself. Why can't I format the output like any other block or page?

  • 1
    If you go into Views and the Style Settings section, there is a Theme Information configuration area that will show all of the templates it uses (and can be overridden). Views actually allows so much theming that I think at times it can be a bit overwhelming, so if you can provide more information on what you are trying to change, it might help narrow down the answer. – Jimajamma Dec 28 '11 at 7:46
  • Ok what I need to do is rearrange the output a little. This is what I am getting – KenAesthetic Dec 28 '11 at 23:02
  • <div class="views-field views-field-title"> <div class="views-field views-field-body"> <div class="views-field views-field-field-thumb"> – KenAesthetic Dec 28 '11 at 23:02
  • I need to put the thumb div at the top then have the title and body come next wrapped in a div called mini_text. – KenAesthetic Dec 28 '11 at 23:03
  • 1
    if you have fields called title, body and thumb, all you have to do is reorder them in the view itself to accomplish most of what you want. to wrap two fields inside one div would require some template mods and views will tell you what one needs to be edited/overridden form the style setting section, but basically you'd want to change your row output. – Jimajamma Dec 28 '11 at 23:14
1

In a nutshell, once you have your view fields ordered in the view itself, you would override views-view-fields.tpl.php to change the row. In there, it has something like this:

<?php foreach ($fields as $id => $field): ?>
  <?php if (!empty($field->separator)): ?>
    <?php print $field->separator; ?>
  <?php endif; ?>

  <?php print $field->wrapper_prefix; ?>
    <?php print $field->label_html; ?>
    <?php print $field->content; ?>
  <?php print $field->wrapper_suffix; ?>
<?php endforeach; ?>

which just cycles through each of those fields and outputs them. So, if you wanted to wrap two fields in a div, you would put some logic like this in there:

<?php if ($id=="MYFIRSTFIELD"): ?>
  <div class="mini_text">
<?php endif; ?>

and put that before the wrapper_prefix php, and put something like this before the closing endforeach:

<?php if ($id=="MYLASTFIELD"): ?>
  </div>
<?php endif; ?>

which would create that mini_text div you mentioned. Anyways, hope this helps, I cut and pasted and coded quickly here, but this should give you an idea of how to do it, even if there are typos in there ;)

  • great! what would MYFIRSTFIELD and MYLASTFIELD be or are these placeholder variables of some sort? – KenAesthetic Dec 29 '11 at 0:23
  • those would be your fieldnames from the view. shove a drupal_set_message('<pre>' . print_r($id,true) . '</pre>') or dsm($id) (or their Drupal 7 equivalent) in there and you can see all the innards you need :) – Jimajamma Dec 29 '11 at 1:47
  • I managed to pull off what I needed with css and just rearranging the field output order. All this seems a little complicated for me but I appreciate the help. I will com back to this to learn what is going on. I know very little php. – KenAesthetic Dec 29 '11 at 2:12
1

I've experienced the same issues with my conversion from D5.x to D6.x and what I ended up doing was to install the Semantic-Views module. It allows, at a row/field level the ability to add classes to each field. Not only does this work well it is a heck of a lot easier than creating and maintaining a tpl.php file. Try it, you'll like it.

  • I am using version 7. It is in development for 7. Should I try it? Read what I am trying to do above and let me know if this module will help. – KenAesthetic Dec 28 '11 at 23:04
  • FYI - I user several modules "dev" version on my production site and they seem to work just fine. I would give it a go to see if it provides what you need. You can always disable/uninstall it if its broken. Trial and error seems to be the normal way of module integration, so I've learned. – bobmct Dec 30 '11 at 4:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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