1

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?

1

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.

https://www.drupal.org/node/1932102#comment-7182640

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)
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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