0
  1. You have a list with Views
  2. It contains titles of nodes.
  3. When clicked those titles redirects to the nodes.

How to make a condition that if e.g. a checkbox is selected in the node saying something like e.g. 'Don't link this to the original content, redirect it somewhere else instead', then overwrite the default path of that node title to something custom?

I found a module https://www.drupal.org/project/views_conditional does it do what I'm trying to achieve?

So e.g. you have a list with 10 nodes titles, 9 of them links to its content, but 1 links somewhere else because it has a checkbox/term selected in the node's settings?

2
  • I'm unsure as to whether you can achieve this through the UI. You could use a hook_views_pre_render() to check whether the node has this condition met and change the markup in the $view object Commented Aug 9, 2018 at 16:18
  • It's possible to hack it together with the UI, though a tpl.php or a hook would be my preferred option. Commented Aug 9, 2018 at 22:49

1 Answer 1

1

You can do this with the UI with some of my favorite Views trickery.


  1. Go to your content type, click the Boolean field and change its Off value to 0.

  2. Create a new view and add the Title field twice. Rewrite the link for one of them, and Exclude both from Display.

  3. Add your Boolean field to the view and..

a. Rewrite the title of this field: [title]

b. No Results behavior: [title_1]

c. Count the number 0 as empty: ✓

d. Hide rewriting if empty: ✓


Because you changed the Off value of the field to 0, you can make Views trigger the No Results Behavior for the field. I've just tested this and it works fine so ask if you have any trouble.

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.