dbusck
February 19, 2016, 6:20pm
1
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.
builder:
label: Sections
type: builder
fieldsets:
projectImage:
label: Image
entry: >
<img src="{{_fileUrl}}{{picture}}" height=180px/>
fields:
picture:
label: Image
type: selector
mode: single
types:
- image
projectImageFw:
label: Fullwidth Image
entry: >
<img src="{{_fileUrl}}{{fwPicture}}" height=180px/>
fields:
fwPicture:
label: Image
type: selector
mode: single
types:
- image
sectionBg:
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?
dbusck
February 19, 2016, 8:27pm
3
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() ?>">
</div>
</div>
</div>
I think I see what is happening. Could you please post the raw field contents from the page that produces the error?
dbusck
February 19, 2016, 9:29pm
5
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.
texnixe
February 19, 2016, 9:53pm
7
Just a quick question, @lukasbestle : Why does the image work and the background does not?
That’s a very good question.
dbusck
February 19, 2016, 9:58pm
9
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.
dbusck
February 19, 2016, 10:02pm
10
Thank you for leading me in the right direction; when I rename the fields to all lowercase with underscore (removing camel casing) it works!
texnixe
February 19, 2016, 10:03pm
11
That explains it, then. But everything should also work fine, if you call the field in your template like this:
$section->sectionbg()
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.