Checkbox is rendering forever truthy in an If/else statement

I’m having an issue with the functionality of the click-thru checkbox I made, The code is as follows but always rendering as truthy in the initial if statement.

foreach($page->children()->visible() as $item): ?>
  <?php if ($item->clickthru()->value()=='turnon'): ?>
    <li>
      <a href="<?= $item->url() ?>">
        <div class="portraitimg">
        <?php

        if ($i > 4) { $i = 1; }
        if (($i == 1) || ($i == 4)) { $image = $item->horzimg()->toFile(); }
        else { $image = $item->vertimg()->toFile(); }

        if($image):
        ?>
          <img src="<?= $image->url() ?>" alt="<?= $page->title()->html() ?>">
        <?php endif ?>
          <div class="text"><strong>View Project</strong></div>
        </div>
        <strong><?= $item->title()->html() ?></strong>
      </a>
    </li>
  <?php else: ?>  
    <li>
     <h1>Worked</h1>
     <div class="portraitimg">
        <?php

        if ($i > 4) { $i = 1; }
        if (($i == 1) || ($i == 4)) { $image = $item->horzimg()->toFile(); }
        else { $image = $item->vertimg()->toFile(); }

        if($image):
        ?>
          <img src="<?= $image->url() ?>" alt="<?= $page->title()->html() ?>">
        <?php endif ?>
          <div class="text"><strong>View Project</strong></div>
      </div>
      <strong><?= $item->title()->html() ?></strong>
    </li>
  <?php endif ?>
<?php $i++; endforeach ?>
  clickthru:
    label: Click Through
    type: checkboxes
    default: turnon
    width: 1/3
    options:
        turnon: Turn On

Hi, @Nathan_Hannon! My first suggestion is that if your interface needs a single checkbox, then you should probably be using a Toggle Field instead.

clickthru:
  label: Click Through
  type: toggle
  default: true
  width: 1/3
  text:
    - turned off
    - turned on

You can then use the ->toBool() method to automatically convert its value for testing in your ‘if’ clause, like this:

<?php if ($item->clickthru()->toBool()): ?>
    <li>
        <a href="<?= $item->url() ?>">

The Checkboxes Field is really meant for when you have a list of items that can be on/off, included/excluded. Therefore, the field returns a list of selected values - not a single value - in a comma-separated list. You then need to split() the list and work with each value individually, as described in the docs.

@kirbyzone You are pointing to the Kirby 3 docs, this topic is about Kirby 2. The method is called bool() not toBool() in Kirby 2.

@texnixe oooops! - totally missed the fact that it’s a K2 question… duh! Did we even have toggle fields in K2? If my answer is out of place, please feel free to delete it!

Yes, there was a toggle field.