Views question

Events happening in the community are now at Drupal community events on www.drupal.org.
Chris Graham's picture

I've got a quick question about views. I was trying to create a completely custom rendering of one of my views and found that you can use the following handler function to render an individual field (in this case an ImageField):

<?php
print $view->field['field_image_fid']->render($row);
?>

The problem is that I tried to get it to work with the node title using:

<?php
print $view->field['title']->render($row);
?>

I had set it to 'link to node' but it only renders the text. I did find a function called render_link within the node handler... but render calls this anyway so it should have output the fully rendered, linked title.

Am I going about this the wrong way? I've decided to give up and use:

<?php
print l($row->node_title, 'node/' . $row->nid);
?>

Just wanted to see if there was a better way of rendering fields in views templates.

Comments

I'm confused as to what you

linclark.research's picture

I'm confused as to what you are trying to do. Could you use Panel Fields for this? There is a screencast about Panel Fields here: http://nodeone.se/blogg/nodeone-talks-drupal-panels-38-and-panel-fields

Sorry, I'm probably

Chris Graham's picture

Sorry, I'm probably overcomplicating the solution in order to stay away from installing too many contrib modules.

Basically I have a content type for conference rooms. It has 4 fields for the seating capacities for different styles of room setup.

For example, one of the rooms has the following options:

Conference Room A
Theatre style seating - 100
Boardroom style seating - N/A
Classroom style seating - N/A
Roundtables - 64

I am creating a view to list all of the conference rooms and link through to the individual nodes for more details like pricing, availability etc.

The view will have an image on the left with a floating section to the right to put the title and a table of seating capacities.

The table of seating capacities is the thing that wouldn't work with Panels Fields... I would still need to do something with that manually in the templates to create the table from the 4 individial fields. I could always make an extra view for the seating capacities using the node id as the argument and render that in the templates... but that sounds a bit overkill.

Its ok as it is, it is working with the code I am using at the moment, I just thought that render() would add the link. If you look at the source code for the handler http://api.zzolo.org/api/drupal/drupal-6-contrib--views--modules--node--... you can see that the render() function calls the render_link() function to add the link when link_to_node is set and it isn't doing when I call it.

Strange thing is that the image field is imagecached and linked to the node and it renders perfectly fine, it is just the title that is causing the issue. Thats why I thought I was maybe doing something wrong.

I think I kinda understand

heather's picture

I think I kinda understand what you're doing, sorta. I wonder if you could use Views attachment. I also assume the reason you have this data in individual fields is so you can sort on values, such as seating capacity, arrangement. In that case you might be using Views exposed filters or some way to help people sort and find what they need. Anyway! I think I get it.

Try this instead, which will print out the title and the link. Is this what you need? Or do you just need the path? This will theme the title along with the path. I think this is a more flexible option than manually creating the link.

<?php
print $view->field['title']->theme($row);
?>

I just put this into my views-view-fields.tpl.php file, and it worked a charm. I found this out from looking at the values in the Drupal Themer Information with the Theme Developer module.

Slightly off topic, I found this video very helpful. Demo of Theme preprocess functions by Carl Wiedemann of GVS from DrupalCon SF http://sf2010.drupal.org/conference/sessions/theme-preprocess-functions-...

Incidentally, I see you were trying to manually parse the path. Most likely you have pretty URLs in effect, so you don't want to revert to node/ID. If you have to do that for some reason, instead of 'node/' . $row->nid you should probably use path. Also, if you just render() title this will returns the string of the value set for the title.

Aha... that makes sense, I

Chris Graham's picture

Aha... that makes sense, I assumed render() would render the themed version... I assumed wrong.

Thanks Heather :)

Ireland

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: