By iansmithdahl on
I have a View that's similar to what you see on a lot of blog listings and the like: basically date, title and a display of the node body limited to a certain number of characters with an ellipsis. What I would like to do is add the option to write a tailor written blurb for the view, if the cribbed node body isn't ideal. So, the View would display the node body field iff the content blurb field was empty.
I can't seem to think of useful google search terms for this. I only get results relating to handling empty Views (like, the whole View is empty).
I'm happy to tweak View configuration or write up code in a tpl.php file, whichever makes more sense and is easiest. Thanks in advance!
Comments
A simple way of doing it
A simple way of doing it would be to output both the node.body field and your custom node.blurb field, and then create a custom views----tpl.php file to display the fields (clear the cache!). In the tpl file conditionally print the blurb or the body.
There is now a sandbox module
There is now a sandbox module called Views If Empty that provides a way to do what you're looking for.
Please follow the steps
Please follow the steps
1. Add both fields
2. make the first one invisible (exclude from display)
3. in the second field go to no result behavior tab.
4. write the token of the first field [field_name].
That should be fine.
Brilliant...
Just came across this today. Got to give credit where credit's due... brilliant approach on this, Ashish. Thanks.
Thanks
ashish.verma85: Thank you, this helped tremendously.
This helped me too
Thanks Ashish for a brilliant way to accomplish this task. Helped me a lot!
+1 For This Approach
Still works with Drupal 8 too, thank you for an easy solution!
Perfect Solution
Thank you ashish. Needed to override a field fed from another department and this solution was the quick fix.
quick and perfect solution
Thanks, ashish, works for my D7
Hi Ashish,
Hi Ashish,
Is there a way I can do the following in my View:
If Field C is empty, then Hide Field B.
Example: Field A is Start Date. Field B is a dash. Field C is Finish Date.
If Finish Date (C) is empty, then hide Dash (B)?
In this case you should be
In this case you should be able to do away with Field B, and then for Field C you would Rewrite Results > Override the output of this field with custom text, and here you would include the dash followed by the Finish date token.
----------
Drupalden.co.uk - Drupal guides, hints, tips...
What can be done for Drupal 8
What can be done for Drupal 8 when the field you want to rewrite is a form, like an add to cart form? Drupal 8 doesn't allow you to rewrite a form like an add to cart form. I am trying to hide the add to cart form in a view when a node is flagged.