Display field only if the content is not empty

Hi,

I have a field (named = “extract”) associated to a page. This field content is supposed to be displayed within the sidebar of the page template.
Some pages have this field filled with content, some other pages have this field blank.
How could I manage to display this field only if the field is not empty (through the template or elsewhere)?
My current code in the template is :

<div><input class="toggle-box" id="identifier-2" type="checkbox" >
<label for="identifier-2">Extrait</label>
<div><?php echo $page->extract()->kirbytext() ?></div>
</div>

I would like to have this <div> displayed only if not empty.
Thank you in advance
Gerard

<?php if ($page->extract()->isNotEmpty()): ?>

  // your code here

<?php endif; ?>

or the other way round …

<?php if (!$page->extract()->empty()): ?>

  // your code here

<?php endif; ?>
2 Likes

Thank you a lot for such a swift answer.
It works perfectly fine !!

Gerard

You’re welcome. By the way, you can find the available field methods here:

http://getkirby.com/docs/cheatsheet#field-methods