1

FINAL UPDATE

Success! Apparently there were field-level permissions set on several of the CCK fields I needed, in spite of the original developer telling me that content permissions were not enabled. Once I allowed anonymous viewing of the required fields, they displayed with no problem.


I've created a view with a block display. The view has a grouping field, and in the views ui preview, the output displays as grouped by that field:

enter image description here

When I display the block using my template, though, it's not printing out the grouping info (Advanced Learning Session or General Session). That field is not a standard one, like title - it's a CCK text field on my content type. How do I access that field in my template? I've tried the solutions shown here to get a list of available fields, but none of them work.

Edited after trying @schnippy's answer

When I mouse over the field, I see this:

enter image description here

So I tried adding

<?php print "session type: ".$fields['field_session_type_value']->content; ?>

to my template, but although the "session type:" string prints, there's no value coming through after it. I've also tried writing just the value to the error log, in case there was something weird about combining it with a text string, but still nothing.

Edit again...

Just to provide a bit more info, if it will help - I'm using the mobile jquery theme, which has a views-view-list.tpl.php file to display views where the output is HTML List. That template looks like this:

<?php
// $Id: views-view-list.tpl.php,v 1.3 2008/09/30 19:47:11 merlinofchaos Exp $
/**
 * @file views-view-list.tpl.php
 * Default simple view template to display a list of rows.
 *
 * - $title : The title of this group of rows.  May be empty.
 * - $options['type'] will either be ul or ol.
 * @ingroup views_templates
 */

?>

<div data-role="collapsible">
   <h3><?php print $title; ?></h3>
  <<?php print $options['type']; ?> data-role="listview">

    <?php foreach ($rows as $id => $row): ?>

      <li class="<?php print $classes[$id]; ?>"><?php print $row; ?></li>
    <?php endforeach; ?>
  </<?php print $options['type']; ?>>
</div>

I have a number of views that are being displayed via blocks with this template, and for the most part it's fine because they all are grouped by a title field. But for one view, the records are grouped by a CCK field called field_session_type_value, and if the value of that field matches a specific value, I want to print that field instead of $title.

Another update

According to views-view.tpl.php, $rows is the variable that views sends out as the results of the view query. Now, if I have multiple fields, I would expect that doing a print_r on $rows would return a multi-dimensional array - each record or row would be an array containing a key/value pair for each field. Like so:

Array (
  [0] => array('title'=> 'Advanced Consumer and Shopper Insight - An Interactive Symposium',
               'session' => 'general-session'),
  [1] => array('title' => 'Creating a Powerful Brand One Dirty Job at a Time',
               'session' => 'advanced-learning')
)

(Yes, I realize my pseudocode array is not formatted correctly. But you get the idea.) But that's not what I'm getting. What it's sending back is a single-dimension array, containing just the titles:

Array (
  [0] => Advanced Consumer and Shopper Insight - An Interactive Symposium
  [1] => Creating a Powerful Brand One Dirty Job at a Time
)

What do I need to do to make sure it sends all the fields through in the $rows array?

0

You're using the 'row style' type 'fields' here, correct? The field you are grouping on should also be added as a field in your 'fields' list in order for this to be showing correctly in your preview so all you need to do is find the name, which can be tricky to guess depending on the cck field type. One way you can do this is by hovering over the 'link' in the fields editor within views:

enter image description here

and get the name of the field from the url in your browser status bar, ex.

../view_name/display/field/<your field name>

and then you just print out the rendered view content of your field in your tpl with:

<?php print $fields['<your_field_name>']->content; ?>
  • Thanks. I just tried that, and it's returning nothing. I'm editing the OP with more info. – EmmyS Feb 1 '12 at 21:32
0

Apparently there were field-level permissions set on several of the CCK fields I needed, in spite of the original developer telling me that content permissions were not enabled. Once I allowed anonymous viewing of the required fields, they displayed with no problem.

Lesson learned; always check for field-level permissions.

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.