0

I have a view that has several decimal fields. I want to output the fields based on their value.

Can I use a view template overwrite and twig if statement for that? Specifically

  1. Output the field value in a variable.
  2. Check the value of field
  3. Based on value add different span around the field output.

Is template overwrite the best approach or maybe I should use a hook?

5
  • I wouldn't recommend neither template nor hook. Rewrite the fields in UI, see drupal.stackexchange.com/questions/218022/…
    – 4uk4
    Dec 3, 2018 at 11:02
  • @4k4 And where do I include the if logic? Can't see that on the question you linked.
    – pierostz
    Dec 3, 2018 at 11:08
  • You can use {% if ... %}
    – 4uk4
    Dec 3, 2018 at 11:12
  • @4k4 Thanks for the input. Works as it should but because the fields have many occurrences a more global approach would be better.
    – pierostz
    Dec 3, 2018 at 13:28
  • OK, this would be a custom views field plugin, you can generate one with Drupal Console.
    – 4uk4
    Dec 3, 2018 at 13:35

0

Your Answer

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

Browse other questions tagged or ask your own question.