I have a view that shows an overview of "experiences". The problem I am having is they switch HTML on every row.

so the first will be:

Image text

then the second will be:

Text Image

I tried using conditionals in the rewrite result. But they seem to not work as shown below:

enter image description here

This outputs:

enter image description here

Is there a fix or workaround for this?

2 Answers 2


By setting field_my_link to show as URLs / plain text I was able to quickly get the result I needed, to point the URL of the title to an offsite URL if it has data, and keep it to the NID url otherwise. view_node is a view field of the URL

{% if field_my_link|length > 0 %}
<a href="{{ field_my_link }}">{{ title }}</a>
{% else %}
<a href="{{ view_node }}">{{ title }}</a>
{% endif %}

This worked quickly and effectively as a rewrite. Although I would rather not have a rewrite stored as config in views, it was a quick and reliable solution.


The following answer is from Drupal 7 post, long time ago but I guess the methodology is still the same.

Basically in your views template you can specify that logic.


if (row is even)
  // display order 1
else {
  // display order 2

Update: There is port of the views conditional module available on github.

https://github.com/anandtoshniwal93/views_conditional/blob/master/README.md You can reuse it in your view like that....

Views Conditional field (if row is even)

  print rewrite field 1 (which is the first combination order)

Viws Conditional field (if row is odd)

  print rewrite field 2 (which is the second combination order)

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.