0

I have a field in my view which displays the taxonomy vocabulary that each result/node is linked to. However, I need a way to get that taxonomy vocabulary result and use it as a class for the view row - not just the field.

Has anyone had any success with something like this before? Options I can think of might be Tokens, direct template theming, or Display Suite, but I don't know how I would go about fetching that vocabulary field output and using it as the row's class.

Any help would be received gratefully :)

2 Answers 2

0

You can achieve this by passing replacement token to row class as shown in figure below:

enter image description here

Update #1

Install Views PHP & add Global: PHP field in view, then enter following values in PHP field

Value code => return strtolower(str_replace(' ', '-', $row->title));

Output Value => <?php echo $value; ?>

Replace [title] with [php] in Row class. Check image below for reference.

enter image description here

2
  • Hi Vishal; that does work! Only one problem. If the content of a [title] field is 'Hi There', then the row class also becomes 'Hi There', when I need it to be 'hi-there'. For a class I obviously need to make the output lowercase and replace the space with a dash. Any ideas?
    – caustic
    Commented Mar 11, 2015 at 9:51
  • Check Update #1 for your query. Commented Mar 11, 2015 at 10:32
0

If you're looking to use it as a class for the whole row rather than just for the field, use a views template.

The Advanced -> OTHER -> Theme: Information section of your view usually has good ideas on what to call files but it doesn't seem to include anything for the row.

If you're using row style: fields... try making a template file called views-view-fields--myviewname.tpl.php.

To dig into the variables available to that template file, the first thing you want to do is install the Devel module, turn it on, and put this in the template:

dpm($content);

or maybe

dpm($output);

dpm() prints the named variable on the screen when the file is run.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.