Structure/builder: can't add second field without error

I have the builder field installed, with several sections. For the example, say I have one fieldset for adding an image, and one to add a full-width image with a background for that section.

      label: Sections
      type: builder
          label: Image
          entry: >
            <img src="{{_fileUrl}}{{picture}}" height=180px/>
              label: Image
              type: selector
              mode: single
                - image
          label: Fullwidth Image
          entry: >
            <img src="{{_fileUrl}}{{fwPicture}}" height=180px/>
              label: Image
              type: selector
              mode: single
                - image
              label: Section background color
              type:  text

The image shows up in the front-end, and in the panel. But the background-color doesn’t, and throws an error:

Notice: Undefined index: sectionBg in .../kirby/lib/structure.php on line 14

I followed the guide on how to access the sections in the plugin readme, so each section has it’s own snippet, named after the fieldset.

Any ideas?

Do you get this error in your template/snippet? If so, could you please post the relevant code from where you call the field?

How I call it in my template:

<? foreach($page->builder()->toStructure() as $section): ?>
   <? snippet( snippet('sections/' . $section->_fieldset(), array('section' => $section)) ) ?>
<? endforeach ?>

And in the snippet sections/projectImageFw.php:

<? $fwimg = $section->fwPicture()->toFile(); ?>

<div class="content" style="background-color:<?= $section->sectionBg() ?>">
   <div class="container">
      <div class="projectImage">
        <img src="<?= $fwimg->url() ?>" alt="<?= $fwimg->title() ?>">

I think I see what is happening. Could you please post the raw field contents from the page that produces the error?

Do you mean like in the content file?

  picture: _50d6601_smaller.jpg
  _fieldset: projectImage
  fwpicture: full_view_k.jpg
  sectionbg: '#f5f5f5'
  _fieldset: projectImageFw

Exactly what I thought: It is written to the file in lowercase.

I have created a fix for this earlier, which is over here. Does it work if you replace this line in your structure.php? If so, this will probably be fixed in the next Kirby version.

Just a quick question, @lukasbestle: Why does the image work and the background does not?

That’s a very good question. :slight_smile:

Actually, thought it wouldn’t matter but when the “fwPicture” is named “picture” (like the other picture field) it works, otherwise it also throws the error.

Thank you for leading me in the right direction; when I rename the fields to all lowercase with underscore (removing camel casing) it works!

That explains it, then. But everything should also work fine, if you call the field in your template like this:


even if its name in the blueprint is “sectionBg”.

Alright. But as I said, this issue should be fixed in the next Kirby version, so your old code should work as well then.