No headline if no content?

Hey all,

I get my tags displayed like this:

<p class="info_head">Services</p>
<p class="info_value">
<?php foreach(str::split($page->services()) as $tag): ?>
<a class="taglist" href="<?php echo url('services:' . urlencode($tag)) ?>"><?php echo $tag; ?></a>
     <?php endforeach ?></p>

if there are no services tagged the “Services” headline still remains. Can I somehow make my loop hide the headline if no service tags are applied?

I guess I’d need separate if/else conditions somewhere, right?

<?php if ($page-&gt;services()): ?>
<p class="info_head">Services</p>
<?php endif ?>

should do the thing.

you mean

<?php if ($page->services()): ?>
<p class="info_head">Services</p>
<?php endif ?>

nope. it wont :pensive:

Check if the value is empty:

<?php  if(empty($page->services()->value())): ?>
…
<?php endif ?>
<?php if (!$page->services()->empty()): ?>
  …
<?php endif ?>

… should also work. See: http://getkirby.com/docs/cheatsheet/field-methods/empty

1 Like

That works! thanks flokosiol!