Yaml loop and checkbox value

Hi. I have problems to get a checkbox variable (‘footerextlink’). The loop looks like this:

<?php foreach($site->footer()->yaml() as $navi): ?>
            <?php if ($navi['footerextlink']) : ?>
                <li><a href="<?= $navi['footernavlink'] ?>"><?= $navi['footernavtext'] ?></a></li>
            <?php else: ?>
                <li><a href="<?php echo $site->url() ?><?= $navi['footernavlink'] ?>"><?= $navi['footernavtext'] ?></a></li>
            <?php endif; ?>
 <?php endforeach ?>

But I Kirby gives me an error:

I rly don’t know what’s wrong!?

Greets, Alex

What are the names of your structure field fields? Maybe a typo?

(I prefer toStructure() over yaml() anyway)

Looks like this … I checked it again and again… :confused: The other variables are working.

footer:
    label: Footer Navigation
    type: structure
    modalsize: large
    style: table
    entry: >
      {{footernavtext}}
    fields:
      footernavtext:
        label: Navigationspunkt
        type: text
        width: 2/4
      footernavlink:
        label: Link zu Seite
        type: text
        width: 1/4
      footerextlink:
        label: Ext
        type: checkbox
        text: Ext Link?
        width: 1/4

Okay… the other way is working:

 <?php foreach($site->footer()->toStructure() as $navi): ?>
              <?php if ($navi->footerextlink()) : ?>
                  <li><a href="<?= $navi->footernavlink() ?>"><?= $navi->footernavtext() ?></a></li>
              <?php else: ?>
                  <li><a href="<?php echo $site->url() ?><?= $navi->footernavlink() ?>"><?= $navi->footernavtext() ?></a></li>
              <?php endif; ?>
<?php endforeach ?>

Are all keys in each entry in the text file? They should be if you use the Panel…

Otherwise, you should check if the key exists. You won’t have that problem with toStructure()-

Edit: You should replace this line:

<?php if ($navi->footerextlink()) : ?>

with this:

<?php if ($navi->footerextlink()->bool()) : ?>

to get the result you want, I think.

Thanks. But in this case I only need to check if the variable exist.

Oh … You’re right ^^ ->bool() is needed

I just realized that bool() does not seem to work as expected.

<?php if ($navi->footerextlink() == '1') : ?>

Edit: And don’t forget to add a slash between your site url and the slug for internal links.