What to do to add additional div just inside the <td> in grid view? Because I need each grid element to have a background color and there should be space between grid elements around 20px.

I have read this guide about theming table views: http://drupal.org/node/154087 but it doesn't seem to work for me (the function names suggestion)

My view (in view HTML source) starts with the following:

<div class="view view-list-of-galleries view-id-list_of_galleries view-display-id-page view-dom-id-2d3795b634708cb7798e1344eb1932af">
  <div class="view-content">
    <table class="views-view-grid cols-3">

Following to the guide, I created a function phptemplate_views_view_grid_list_of_galleries($view, $nodes, $type) in template.php but there is no change in the view and this function is not called at all (I used "grid" in place of "table").

Comments

dawehner’s picture

Status: Active » Fixed

You should create a .tpl.php file for that, there it should be pretty easy to add another div.

Status: Fixed » Closed (fixed)

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

philsward’s picture

Status: Closed (fixed) » Active

Sorry to re-open this, but I also agree that this issue should be taken care of out of the box. A simple div to wrap the entire contents inside the <td> would be sufficient. I agree that you can create the template file, but the template file really should be used for extensive modifications of the view, not a simple div and class addition that, IMHO, should be there in the first place.

This isn't the first time I've run into this exact same problem and quite frankly, I'm surprised more people haven't raised a stink about it. Without that simple div wrapper, it's impossible to set background colors to a with spacing between them or create borders with spacing between them.

My last solution was to create the tpl file. I probably spent an hour playing with the CSS before I decided the only way I could make it work, was to add the div in a .tpl. Well, time has passed since the last time I had to do it and guess what... I just spent another hour trying to figure it out before realizing, the tpl file is the only solution. I guess my question is: "if people expect it to be there, wouldn't it make sense to add it?"

It's like selling a car without paint. You guys are telling us to: "just create a .tpl". The car salesman is telling people: "Go get it painted".

chaloum’s picture

No need for a TPL just set the fields to not display and in the last field re-write the results including the div the that results will be contained within.

philsward’s picture

@chaloum Seems like a lengthy workaround... I'll check it out though.

dawehner’s picture

Status: Active » Fixed

Yeah for rewriting the results!

Status: Fixed » Closed (fixed)

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

s@ilor’s picture

@ chaloum

I think I understood you most of the way. Could I ask you to elaborate on this? Especially on the bit that contains the other fields ...?

Thanks,

chaloum’s picture

@S@ilor

Ok here goes, in the FIELDS area of views except for the last field you need to set each field to "Exclude from display" otherwise everything will double up.

its best the the last field in the list is Body or Title but its important that this field displays.

Now open the field and click on the link, REWRITE RESULTS and a it should open up

Check the Rewrite the output of the field checkbox and in the Text field use the Tokens (as seen in the Replacement Patterns link below the text field)

The the tokens are fields wrapped in [] so [body] [title] [image_field] etc there

so in the text area you could do something simple like

[title]
[field_image] [body]

or more complex like

<h2>[title]</h2>
[php_2]
<div>[body]</div>
<p id="PriceDisplay">[field_item_price]</p>
<div class="item-price">[php] </div>
<div>[field_framed_price]</div>
[edit_node]

don't forget to save, but you will get there

So in a nutshell

  • stop all field from displaying except the last field in the list
  • in the last field turn on Rewrite Results
  • and tokens and html as required
  • save

Marcel
EDMEDiA Web Design