1

Our client saw the schedule view of DrupalCon Denver's site and wants one of their conference schedule views to look like that:

enter image description here

Obviously we're styling things differently, but what they really want is the track icons to display in the exposed filter and alongside the individual sessions.

Individual Sessions We have a content type called session, and a taxonomy called track. The taxonomy has an image field called track icon (field_track_icon), and there's a term reference field on the session that holds the selected track.

I managed to get the icons to display in the view with the sessions:

View setup - View setup

Preview - preview

But I need to do some conditional processing - if the field "field_hide_track" on the individual session is true, then don't display track icons (or the value of field_hide_track, obviously.) We have a certain session type that needs to contain all of the choices from the taxonomy (i.e. be associated with all tracks) but do not want it to have a visual indicator. Right now, because they have all the choices, the view displays all of the icons from the taxonomy. It also displays the icon twice if there are multiple speakers, but I think that's because of the way we have things grouped. Basically we want the icon to display before the session number/title line for all sessions that don't have field_hide_track checked.

I've tried custom templates (views-view-fields--at-a-glance-test--page.tpl.php and views-view-field--at-a-glance-test--page.tpl.php, where the view's machine name is at_a_glance_test), but can't figure out how to get the information I need to do the conditional processing. Can someone point me in the right direction?

Exposed filter I have no idea where to start with this one. We're using Better Exposed Filters module to allow checkboxes instead of dropdowns, etc. I already have a views-exposed-form template to handle the background color and font choices, etc. but aside from some kind of horrible hard-coding, I don't know how to get the icons from the taxonomy to display next to the checkboxes. I think I could probably move the css for this into the template file and generate a background property for each taxonomy term that would include the image, but I don't know how to get the image from the taxonomy term field in the context of the views-exposed-form template.

EDIT to add Views PHP code that worked

<?php
if(isset($data->field_field_hide_track[0]['raw']['value'])) {
    if($data->field_field_hide_track[0]['raw']['value'] == '0') {

    $image_vars = array(
        'path' => file_create_url($data->field_field_track_icon[0]["rendered"]["#item"]["uri"]),
        'alt' => $data->field_field_track_icon[0]["rendered"]["#item"]["alt"],
        'attributes' => array(
          'class' => array('session_list_track_logo')
        )
      );

    $track_logo = theme('image', $image_vars);
    print "<h3>" . $track_logo . " " . $data->field_field_session_number[0]['raw']['value'] . " | " . $row->title . "</h3>";
    }
    else {
      print "<h3>" . $data->field_field_session_number[0]['raw']['value'] . " | " . $row->title . "</h3>";
    }
}

?>
0
  1. To show fields you have to use views_php where you can check

    if ($row->field_hide_track) { print $row->field_track_icon; }

  2. For filters you are on the right track you are showing terms as checkboxes you just have to style labels of the field just like DrupalCon Denver's site something like this.

    views-exposed-form-schedule-page .form-item-edit-track-1 label, #views-exposed-form-schedule-page-1 .form-item-edit-track-1 label, #views-exposed-form-schedule-page-2 .form-item-edit-track-1 label {

    background: url(/sites/all/themes/denver2012/images/track-1.png) 0 0 no-repeat; }

  • Thanks, I'll look at views_php. As for the exposed filter, I don't think I was clear on what I need to do. I know I can create a style like that; the issue is that I need to get the url of the graphic from the taxonomy term field. – EmmyS Jun 6 '12 at 20:04
  • If you want to show field_track_icon you have to write html in labels for this you have to override theme_select_as_checkboxes function from better_exposed_filters.theme in your theme and when bef_checkbox is called in theme_select_as_checkboxes it removes label html so you have to also write new function your_bef_checkbox where you can load term using taxonomy_term_load($value); and insert field_track_icon in your label – jibran Jun 6 '12 at 20:44
  • OK, I've looked at views_php, and based on the issue queue and all the comments, there are way too many bugs and issues to be useful in D7. Any other ideas? – EmmyS Jun 6 '12 at 21:44
  • I have never faced any issue using views_php and so are 11,415 other sites. Just try to use it. It works fine. If you don't want to use it then you have to overwrite fields level template in views views-view-fields--at-a-glance-test--page.tpl.php and put some php code there. But I strongly suggest to use views_php. – jibran Jun 6 '12 at 21:53
  • I've already tried. I spent 3 hours this afternoon trying. There are issues, big ones, with 7. The $rows>whatever variables only display node ids, not actual values, and there's no easy way to get an image field. – EmmyS Jun 6 '12 at 23:25

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.