1

My scenario:

  • a field (color_field) to enter a color code (ie: #fafafa)
  • in Global: Custom text in Views use the token of color_field to generate a border color (is: style="border-color: [color_field]")

Then, I must display for each row a different border-color and the color code is generated with a color picker in color_field when add a new node.

Unfortunately the inline CSS is stripped from Global: Custom text in Views.

How I can use inline css in Global: Custom text in Views?

Or have I to change approach to my scenario?

5
  • inside global area use: <span class="myclass">CONTENT</span>, or similar, then in sub/theme/mycustom.css add .myclass {display:inline} or whatever.
    – pinueve
    Jun 12, 2017 at 14:10
  • I must use inline CSS because color_field is a hexadecimal color code generated with color picker.
    – kb8
    Jun 12, 2017 at 14:18
  • what i ment is: do not use css inside global field, instead add classes, and css goes in subyheme/yourcuestomfile.css
    – pinueve
    Jun 12, 2017 at 14:23
  • Yes, but I must display for each row a different border-color and the color code is generated with a color picker in color_field when add a new node. I can't allow at the user to edit a css file.
    – kb8
    Jun 12, 2017 at 14:36
  • you are in the rigth track, (also with my comments) but you'll need a preprocess (on node, row, views ...) function to acomplish it, dig more what function is the rigth one for you. your field value is inside row variable, you can not extrapolate this value to use it in the whole row.
    – pinueve
    Jun 12, 2017 at 14:46

1 Answer 1

2

I've solved overriding view-view-field--field-myfield.tpl.php and in template file I've used color from $row variable.

<?php 
$title = $row->field_field_myfield[0]['rendered']['#markup'];
$color = $row->field_field_myfield_color[0]['rendered']['#markup'];
?>
<h3 style="border-color: <?php print $color ?>"><?php print $title ?></h3>
1
  • 2
    As far as I know, a template is the only way to do this. Jun 13, 2017 at 12:16

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.