klox7 VIP
Total posts: 914
13 Dec 2013 07:50

Hello,

I want to make a simple change beetween two image fields. I would like to display 1st image field only if 2nd one is empty. If 2nd one has value I would prefer to display 2nd one! And if there is no value display none.

I'm asking if it is possible to check if field has value?

Last Modified: 02 Mar 2014


Konstantin
Total posts: 1,113
15 Dec 2013 23:21

Yes, you can check it, but you must create your own custom template for it, and use something like this.


if(isset($item->fields_by_key[key_of_field]->result)) echo $item->fields_by_key[key_of_field]->result ;

klox7 VIP
Total posts: 914
23 Dec 2013 02:04

Here is the code just to show results. But it is more like if field2 has value than show field2 otherwise show field1.

<?php if(isset($item->fields_by_id[field2id])): ?>

    <div id="<?php echo 'field-rslt-'.$item->fields_by_id[field2id]->id; ?>" class="<?php echo $item->fields_by_id[field2id]->fieldclass;?><?php echo ($item->fields_by_id[field2id]->params->get('core.label_break') > 1 ? ' line-brk' : NULL) ?>">

        <?php echo $item->fields_by_id[field2id]->result; ?>

    </div>

<?php elseif(isset($item->fields_by_id[field1id])):?>

    <div id="<?php echo 'field-rslt-'.$item->fields_by_id[field1id]->id; ?>" class="<?php echo $item->fields_by_id[field1id]->fieldclass;?><?php echo ($item->fields_by_id[field1id]->params->get('core.label_break') > 1 ? ' line-brk' : NULL) ?>">

        <?php echo $item->fields_by_id[field1id]->result; ?>

    </div>

<?php endif; ?>
Powered by Cobalt