Download & Extend

Get values of the field by field_id from $row

Project:Views
Version:6.x-3.0-alpha3
Component:Documentation
Category:support request
Priority:normal
Assigned:Unassigned
Status:closed (fixed)

Issue Summary

Problem
Excluded from display field (with multiple values) totally disappear from view if cheeked "Group multiple values" option.

Conditions
1. In CCK create Text_Field with number of values = 2, and checkboxes widget
2. Create View (node view) with Text_Field and some other fields
2. In Text_Field check "Exclude from display" and "Group multiple values" (2 values beginning from 0)

Expected result
The Text_Field is included in row view object (visible for theming) by $row->node_data_field_text_field_value

Actual result
Text_Field not visible for theming if "Group multiple values" cheeked.

If uncheck "Group multiple values", then this field included as expected and it is easy to check by functions:

<?php
drupal_set_message
('<pre>' . var_export($row, true) . '</pre>');
?>

If uncheck "Exclude from display" and leave cheeked "Group multiple values" it works as expected -- it returns united values in any view display.

So, i believe, the problem is in combination of "Exclude from display" and "Group multiple values" options.

Comments

#1

Category:bug report» support request

Well, the problem is a little easy -- when "Group multiple values" is checked then this field is disappear from $row array in template file (it is no relation with "Exclude from display" options).

So the question is how can i find value of grouped multiple values field in .tpl file?

#2

Title:Exclude from display & Group multiple values» On "Group multiple values" field dissapear from $row

#3

Status:active» closed (works as designed)

It's not that the values disappear from $row, it's that they were never there.

The $row is the raw results of the query. However, when utilizing fields in a many to one relationship (such as taxonomy terms, user roles and CCK fields that can have multiple values per node) you cannot get this raw data in the query. Therefore it will not appear in the $row variable.

The rendered output should still appear as normal. Perhaps it would be easiest if you simply didn't exclude it. The field handler itself is responsible for keeping the raw data somewhere, so at best that data is probably on the field object ($view->field[$field_id]) but the form that data will take will vary from handler to handler as Views does not impose any limitations on how it does it.

#4

Aha! Thank you for explanation and recommendation!

#5

Title:On "Group multiple values" field dissapear from $row» Get values of the field by field_id from $row
Component:Views Data» Documentation
Status:closed (works as designed)» active

Ok, after 2 days of *^$%)@ and reading hundreds issues, forums, and patient explanations of Earl I get values of the field by:

<?php
$row
->{$view->field['FIELD_ID']->field_alias}
?>

pretty simple, ha?

Is it good idea to write some more help in template files, and to update page in Advanced Help? This can save thousands of hours of people who are looking for answers.

In Advanced Help page it is proposed to use only

<?php

print $row['title'];
?>

for to get fields values in template files. But it is extremely necessary to give examples of more complex cases from the creator of module. This would reduce the noise level at the isuues queue, and release many time of mantainers.

I, unfortunately, can't do compilation of available information, because of poor language skills. So i open this issue again for get attention on this.

I am sorry if it is an old hackneyed idea and there are reasons on which it is not realised yet.

#6

Certainly more examples in the advanced help would be welcome. Sadly very few people have come forth to offer their authoring talents in writing better documentation than I have there, and I have a vast, vast array of items on my plate. Improving this documentation has not been high enough on my priority list to be done.

#7

Reading your example a bit, there may also be some confusion. Some of this confusion is a core mistake I made in the templates that is, unfortunately, not fixable now because it would break people's sites.

That mistake is that $row variable is actually overwritten in some templates. And not others. The templates are not consistent with each other. So reading instructions for one template does not work on a different template, and that leads to 2 days of hair pulling.

#8

I create new section at http://groups.drupal.org/node/4161 -- "Theme Views 2 from template files" and write some examples from my (may be wrong) experience.

#9

Thank you for the explanation, but $row->{$view->field['FIELD_ID']->field_alias} does not work for me if "Group multiple values" is checked. I've read http://groups.drupal.org/node/4161 but I'm not sure what to do.

Should I use $rendered_value? Is it possible to use it in template.php as well?
Or maybe I should use $row_value = $row['COMBINED_FIELD_ID']? (but I don't know where to get COMBINED_FIELD_ID).

Thank you in advance for help.

#10

Hi,

I'm currently working on a template file called views-view-unformatted--myview.tpl (style output).

<?php if (!empty($title)): ?>
  <h3><?php print $title; ?></h3>
<?php endif; ?>
<?php foreach ($rows as $id => $row): ?>
  <div class="<?php print $classes[$id]; ?>">
    <?php print $row; ?>
  </div>
<?php endforeach; ?>

My question: how can I display a specific field in this template view? print_r($rows) give me nothing :(

Thanks

#11

Status:active» fixed

<?php
  $view
->style_plugin->rendered_fields
?>

#12

Status:fixed» closed (fixed)

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

#13

Version:6.x-2.8» 6.x-3.0-alpha3
Status:closed (fixed)» active

@ #11 - Is this still valid with Views 3.0-alpha3?
I'm trying to print the value of CCK field.
View Style: Unformatted
Row Style: Fields
CCK field name: field_question_totalanswers

Content of "views-view-unformatted--questions-pool.tpl.php"

<?php if (!empty($title)): ?>
  <h3><?php print $title; ?></h3>
<?php endif; ?>
<?php foreach ($rows as $id => $row): ?>
  <div class="<?php print $classes[$id]; ?>">
    <?php
         
print $row;
          print
$view->$row->field_question_totalanswers;
   
?>

  </div>
<?php endforeach; ?>

#14

Status:active» closed (fixed)

RE #13
Figured that node has to be loaded before i could print the value of CCK field of node.

<?php $node=node_load($view->result[$id]->nid); ?>
<?php print $node->field_question_totalanswers[0]['value']; ?>