I'm trying to solve a complex problem with views. I've got rows of rewritten semantic views data. There are certain rows that need a special class added to the HTML if the node has a particular parent tax term. I can easily include the taxonomy term as a field and include it as a data value in the HTML, but the problem is that not all nodes have the parent term checked, nor can I expect them to.

I'm able to get the parent term in views_pre_render by calling taxonomy_get_parents, but I cannot pass this information to the front end. This view is using semantic views, so no normal views markup is used and the entire result is rewritten.

The fields that I'm using are just title, date, taxonomy, path and an image.

  • In your views_pre_render, can you see the field with the HTML that you need changed in the dpm output if you do something like this: $results = &$view->result; foreach ($results as $key => $result) { dpm($result); } Jun 6, 2016 at 3:40
  • I looked for it but I could not find the rendered output. I did exactly that by looping through the results and running a dpm on each one. I don't believe the final render is available at this point.
    – Hawkee
    Jun 6, 2016 at 3:48
  • I believe your row is rendered by the first function of semanticviews_plugin_style_default.inc try to add dpm $options['row'] after this see if you can see the HTML there: // Row option definition. $options['row'] = array( ... ); dpm($options['row']; return $options; Jun 6, 2016 at 12:30
  • @longboardnode I'm not exactly clear what your solution is taking this route. I used semantic views to remove the divs for each row, so the only markup this view returns comes from the rewritten last field. I wonder if I can just add any old field to the list, add it as a class name in the HTML and use views_pre_render to replace that value with my custom class.
    – Hawkee
    Jun 7, 2016 at 16:20
  • 1
    Yes, you can do that but AFAIK the type of the field you add must correspond to the type of value you replace in your views_pre_render, so if you replace value with text, the old field you add must be text too. Jun 7, 2016 at 21:38


Your Answer

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

Browse other questions tagged or ask your own question.