drupal-7drupal-taxonomytaxonomy-terms

drupal 7 Can't to get value of field from taxonomy in inside view template


i have a view that display bunch of tasks. The task is a content type, one of its field is a reference to taxonomy called theme. The taxonomy theme has a field that reference to another taxonomy named subarea. The subarea taxonomy has field contains a color. I want to change the background of the view title as the color of the subarea. Because i am a beginner i don't know how to achieve that. i could only start by override my view template. But i couldn't load taxonomy term.

/* views-view-unformatted--aufgaben.tpl.php

   View reference field as a RELATIONSHIP:"field_task_themen" from taxonomy "Theme".
   Field from taxonomy "Theme" that reference to subarea taxonomy : field_tax_subarea_ref
   Field from subarea that store the color: field_tax_subarea_color 
*/

 // static color works
<?php
    $color ="green";
?>
<?php if (!empty($title)): ?>
    <h3 style='background-color: <?php print $color ?> '><?php $title;?>
    </h3>
<?php endif; ?>

Solution

  • As you are a beginner then congratulations because you are overriding a views template, which is not a beginner thing.

    I suggest to look the default templates that can be overriden, read the comments in those templates, and pay special attention to which vars is views passing to you. If none of this is familiar to you, you can override a template and start passing the variables through dpm function to see its contents.

    In essence, you have to pick a template which have access to the taxonomy term ID, then load it with taxonomy_term_load https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.module/function/taxonomy_term_load/7.x

    Just in case, an easy way to "print" variable values is using the function dpm, you must activate the developer module to access this function.

    Hope that helps.