Working checkbox example?

Hello,

I’m new to Kirby and trying to get a checkbox panel field working, but am having trouble.

Here’s my blueprint definition for the field:

  header:
    label: Header 
    type: checkbox
    text: test

Here’s my php:

<?php if($page->header() == 1): ?>
  <?php snippet('contact') ?>
<?php endif ?>

Which causes it to show on every page. I’ve also tried:

<?php if($page->header()->bool()): ?>
  <?php snippet('contact') ?>
<?php endif ?>

But then it shows on zero pages.

All my other fields for the blueprint are working just fine.

In the article content files, I see:

----

Header: 

And then when defined:

----

Header: 1

I’ve tried setting the non-checked values in the content files to 0, but that doesn’t make a difference.

Any help would be appreciated!

Thanks,
topher

The checkbox returns a bool, so your code:

<?php if($page->header()->bool()) :?>
 //do stuff
<?php endif ?>

should work, so it’s not a problem with your code.

BTW: Have you turned debugging on in your config.php (c::set('debug', true);)? Because your first if-statement should have thrown an error, because the “1” in your content file is not an integer …

Well - I had moved the blueprint field definition up in the file and then everything worked. Then I switched on debug in the config, moved the section back to the last field in the blueprint, and everything still works. I can’t reproduce the issue…not sure what changed, my guess is that I had an unprintable character in the field definition and moving the section around fixed the problem.

Thanks for the reply!

hi.

<?php if($page->weights()) :?>
	 <?php echo $page->weights() ?>
<?php endif ?>

my checkbox blueprint works with multiple checkboxes.
the output in the template is seperated with kommas.

how can I separated the single values with spans or li tags?

$checkboxes = $page->weights()->split(',');

gives you an array you can then loop through.