Hi there,

I know that there are alot posts around here with this, or the same topic. My problem is that I don't get it work the way I want to. Until today I mainly worked with Drupal 5.x and Views1, and it was really easy to create own templates, but I think I don't understand the way it's working with Views2.

In Views1 I created a template for my views, like views-list-whatever.tpl.php, placed the code in the template.php, and then I was able to rearrange all the fields within the views-template.

Is it possible to have it the same way in Views2? Let's say my views is called "testviews", how can I create one file with all fields in it, if the fields are called... field_one, field_two, field_three?

Sorry if this may be a stupid question. The other problem ist that I am not that into php, so it was more easy for me with views1.

Anyway, maybe someone can help me on this. Thank you very much in advance,

Yucom

Comments

merlinofchaos’s picture

Status: Active » Fixed

You have to do a little bit more manual work to accomplish this. But if you use the 'unformatted' style, and you look at the template, you'll see that all this template is actually doing is looping through the $fields array and printing each field exactly the same way. If you want to print each field individually, you can. Just look at the contents of this array. To be more precise, you can get the list of field IDs from the theme: information page. Then, instead of looping, you can print $fields['FIELD_ID']->content (and the various other items that are in $fields['FIELD_ID']) as you like.

Yucom’s picture

Thank you very, very much merlinofchaos. I'll try it later today and hopefully it'll work. Would be great. :) But if you say so, it should work. ;)

Thanks again for your help!

Yucom’s picture

Status: Fixed » Active

Okay, I think I have to ask again. Sorry for this.

I now created a new view called testview. There are 4 fields in it, title, body, and two cck fields.

I then created a template called views-view-unformatted--Testview.tpl.php, and refreshed everything. Everything is working fine until this point.

Then I try to edit the template, and this is what it looks like:

<?php
// $Id: views-view-unformatted.tpl.php,v 1.6 2008/10/01 20:52:11 merlinofchaos Exp $
/**
 * @file views-view-unformatted.tpl.php
 * Default simple view template to display a list of rows.
 *
 * @ingroup views_templates
 */
?>
<?php if (!empty($title)): ?>
  <h3><?php print $title; ?></h3>
<?php endif; ?>

<?php print $fields['body']->content;  ?>
<?php print $fields['field_test_value']->content;  ?>    
<?php print $fields['field_test2_value']->content;  ?>

The IDs have been taken from the Information-Page. After I saved, uploaded and refreshed everything, nothing is diplayed on the view page.

What did I do wrong here?

Thanks for any help again!

merlinofchaos’s picture

Sorry, this is my bad. I gave you the wrong template. It's the unformatted style but the important thing is the *row style* which is probably 'Fields'. For that it's views-view-fields.tpl.php -- and there's a large block of documentation at the top of the template that tells you what data is in what variable.

Yucom’s picture

Status: Active » Fixed

Okay, now it's working, great! :)

Thank you so much again for explaining it to me! Now, after I got it it's even easier then in version 1. :)

Tanks again!

merlinofchaos’s picture

Title: Theme Views again » Explain how to theme the row style like this
Category: support » feature
Status: Fixed » Active

There's already some commentary in the advanced help about this, but I think this deserves a better, more concisely written page, with a good solid example so that questions like this can be answered with a link to it. Changing to feature request for that documentation (and am willing to accept contributions!)

Yucom’s picture

Maybe I can ask another Question on this, sorry if I am bugging you. Just ignore me if I am too annoying. :)

I did what you said above, and it worked fine so far, but then i recognized another "Problem".

For example:

I creating a template like you said and I was able to place my field in it. Then I startet to theme them, like this:

<div><?php print $fields['field_test1_value']->content;  ?></div>
<div style="float:left;"><?php print $fields['field_test2_value']->content;  ?></div>
<div style="float:left;"><?php print $fields['field_test3_value']->content;  ?></div>

(just an example)

I also did some padding and margin, and then I refreshed everything. I then recognized that it wasn't what I expected based on my css, etc. I had a look on the code with firebug, and I saw that views made each div a row, so that it really messed up everything.

My question now is: Is it possible to have it completly without any stlye, like a row style, etc?

The cool thing with views one was that I just created the templates, and then changed the list style via return implode(" ",$items); in the template.php. After this I was able to do what ever I wanted to do, use divs, tables, whatever.

Did I do something wrong here, or is it just not possible to do it this way?

Cos of this I changed back to 5.x for my actual project. But for future projects I want to use 6 again.

Thanks for your help again, I appreciate it!

Take care,

Yucom

esmerel’s picture

Assigned: Unassigned » esmerel

Assigning to myself to try to update the documentation some.

iamjon’s picture

One of my favorite explanations on unformatted row style theming comes from here:
http://mustardseedmedia.com/podcast/episode30

@merlinofchaos #6 were you referring to using-theme.html?

esmerel’s picture

Status: Active » Fixed

Added some details to the style-row page about unformatted styles and row templates.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.