Hello,
I have Views with multiple row fields being output. One of them has the option: [x] rewrite output on. The field name is wrapped in a div which adds drop shadow CSS effects on the image in question like so:
My problem is that not all content items have an image loaded, and so the field sometimes has a null between the div tags:
Ideally Views would not render a field when the [image_field] is blank, but it still does, which means I get a drop shadow printed to the output on a page where there is no image...
I tried to put a PHP script inside of the [x] rewrite output box, but the PHP is ignored [it just outputs to the browser the encapsulating <?php string.
So, my question is:
1. is this a limitation of Views?
2. is there a work-around?
3. if the answer to the first two is Yes and NO [respectvly], then; could I please list this item as a feature request?
I hope there is a solution, as this is fairly limiting to my project -- thanks so much for your time!!
Kindly,
Sebastian
Comments
Comment #1
schedal commentedComment #2
schedal commentedSorry, forgot to add wrapping "code" tags to the above example, it should be:
Comment #3
merlinofchaos commentedThere is a textbox to tell Views what to display if the field is empty. That will override rewriting, I think.
If all else fails, you can work around this by theming the field via a template, where you can use all the PHP you need.
Comment #4
schedal commentedHi Thanks for your response, if you mean the option:
Basic Settings->Empty text-> type in the box what you want displayed when the View is empty, this is works on a View level, not a field level. There are no options on the field-level to suppress output when the field value is empty.
If I approach it from a template.php level, I am wondering if there is a way to write some kind of PHP code that would apply to ALL fields in ALL views; something like:
although this would have to happen BEFORE the rewrite output occurs, and not after... is it possible to affect the View template with a pre-process hook?
As really I would need this ability to supress rewrite fields on lots of different fields on many different projects I am doing [now and in the future] so I'd like a general solution I can just apply to all of them; as I really feel that Views should ALWAYS supress the rewrite field when there is no content; as that seems logical in any usecase situation I can imagine. So smarter than me creating separate template.php files for each view...
Thanks!
Comment #5
merlinofchaos commentedThere is an empty text for each field, too.
Comment #6
merlinofchaos commentedIt's very new, so be sure you have av ery recent version of Views. 2.7 at least in the 2.x line.
Comment #7
schedal commentedYaay! you rock, thanks for making this feature!