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:

[image_field]

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

schedal’s picture

Title: how to supress "rewrite output" when token is NULL or use PHP in that field? » how to supress "rewrite output" when value is NULL or use PHP in that field?
schedal’s picture

Sorry, forgot to add wrapping "code" tags to the above example, it should be:

<div class="dropShadow">[image_field]</div>
merlinofchaos’s picture

There 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.

schedal’s picture

Hi 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:


<?php
for each $view_row {
 if ($content) { print $content; } ?>
}

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!

merlinofchaos’s picture

There is an empty text for each field, too.

merlinofchaos’s picture

It's very new, so be sure you have av ery recent version of Views. 2.7 at least in the 2.x line.

schedal’s picture

Status: Active » Closed (fixed)

Yaay! you rock, thanks for making this feature!