Home Ask Login Register

Developers Planet

Your answer is one click away!

Steef0w February 2016

How do I hide the div if the Var is empty?

I am trying to hide an entire piece of CSS, a field, when the result of the vr is empty. How should I get this done? I currently managed to make sure that when the data is empty in the database, it doesn't display anything at all, otherwise it does.

<div class="row row_border">
    <div class="col-md-2 col-sm-2 col-xs-3"><div class="icon"><span class="icon-tree101"></span></div></div>
    <div class="col-md-10 col-sm-10 col-xs-9">
        <div class="row">
            <div class="col-md-12 col-sm-12"><h4>Buitenruimte</h4></div>
            <div class="col-md-6 col-sm-6 list_name">
                <?php if (empty(Vars::$content->object->data['obw_tuintype'])) { echo "";   } else { echo (Vars::$content->object->data['obw_tuintype']); } ?>
            </div>
        </div>
    </div>                             
</div>

that's the code I have so far, thanks.

Answers


Ben February 2016

Why not put the if statement outside of the div? That way, if the element is empty, the entire div won't be displayed at all:

<?php if(!empty(Vars::$content->object->data['obw_tuintype'])){ ?>
    <div class="row row_border">
        <div class="col-md-2 col-sm-2 col-xs-3"><div class="icon"><span class="icon-tree101"></span></div></div>
        <div class="col-md-10 col-sm-10 col-xs-9">
            <div class="row">
                <div class="col-md-12 col-sm-12"><h4>Buitenruimte</h4></div>
                <div class="col-md-6 col-sm-6 list_name">
                    <?php echo (Vars::$content->object->data['obw_tuintype']); ?>
                </div>
            </div>
        </div>                             
    </div>
<?php } ?>

Post Status

Asked in February 2016
Viewed 1,966 times
Voted 8
Answered 1 times

Search




Leave an answer


Quote of the day: live life