Kirby Builder: Call to a member function _key() on string

Hi Community,

we are a small digital agency and are trying to build our new website with kirby. currently we are using the kirby page builder to be flexible with content elements. i hope this is the right approach.
now we just have a problem, which is only on the remote server. in the local development environment it works without problems.
in the default template we have the following code to retrieve the content from the page builder:

<?php
        foreach($page->mybuilder()->toBuilderBlocks() as $block):
            snippet('blocks/' . $block->_key(), array('data' => $block));
        endforeach;
   ?>

This error message is shown:

Call to a member function _key() on string

We have 5 Block Snippets. if necessary, I will post them as well.
Could anyone help please? Thanks!

Could you post the blueprint, please?

It’s probably an issue with the field name or stuff not being readable. Does the rest of the content render correctly?

Welcome to our community!

Default.yml

title: Default Page
preset: page
fields:
  #text:
    #label: Text
    #type: textarea
    #size: large
  mybuilder:
    label: Seiteninhalt
    type: builder
    columns: 1 # Optional. If set to 2 or more, the builder blocks will be places in a grid.
    max: 10 # Optional. Limits the number of builder blocks that can be added.
    fieldsets:
      section:
        label: Section <strong>{{identifier}}</strong>
        tabs:
          content:
            label: Inhalt
            icon: edit
            fields:
              sectionfields:
                type: builder
                label: Section Content
                fieldsets:
                  bodytext: blocks/bodytext
                  img: blocks/img
          settings:
            label: Settings
            icon: cog
            fields:
              identifier:
                label: ID
                type: text
                width: 1/2
                placeholder: ID
              animation:
                label: Animation
                type: select
                width: 1/2
                options:
                  fadein: FadeIn
                  fadeinup: FadeInUp
                  fadeinupbig: FadeInUpBig
                  fadeinleft: FadeInLeft
                  fadeinleftbig: FadeInLeftBig
                  fadeinright: FadeInRight
                  fadeinrightbig: FadeInRightBig
              style:
                label: CSS Klassen
                type: checkboxes
                width: 1/2
                options:
                  text-white: weißer Text
                  is-full-height: Full Height
                  is-middle: vertikal zentriert
                  is-bottom-mob: mobil bottom
              container:
                label: Container
                type: radio
                width: 1/2
                default: container
                options:
                  container: normal
                  container-stretched: volle Breite 
                  container-stretched-paddings: volle Breite mit Abstand
              info:
                text: **Bitte beachten!** Parallax funktioniert nur bei Auswahl eines Hintergrundbildes. Hintergrundfarbe funktioniert nur ohne Hintergrundbild.
                width: 1/1
                type: info
              bgcolor:
                label: Hintergrundfarbe
                width: 1/3
                type: select
                options:
                  bg-primary: Primärfarbe
                  bg-dark: Dunkel
                  bg-bright: Hell
              bgimg:
                label: Hintergrund-Bild
                type: files
                multiple: false
                width: 1/3
              parallax:
                label: Parallax-Effekt?
                type: toggle
                width: 1/3
      quote: blocks/quote
      bodytext: blocks/bodytext
      events: blocks/events
      img: blocks/img

quote.yml

label: Quote
preview: # Optional. If defined, a preview of the block can be rendered by the specified snippet from within the snippets folder
  snippet: blocks/quote
  css: /assets/css/blocks/quote.css
fields: 
  text:
    label: Quote Text
    type: textarea
  citation:
    label: Citation
    type: text

bodytext.yml

label: Textblock
tabs: # Optional. Tabs can be used to group the fields of a field set. In this example, we use one tab to contain the content related fields and one for styling settings. Is makes no difference for the contentn handling in the template if there are tabs or not.
  content:
    label: Inhalt
    icon: edit # Optional. This icon appears next to the tab. The icon name can be chosen from the Kirby's icon set getkirby.com/docs/reference/ui/icon
    fields:
      text:
        #label: text
        type: textarea
  style:
    label: Style
    icon: cog
    fields:
      fontfamily:
        label: Font
        type: select
        options:
          helvetica: Helvetica
          comicsans: Comic Sans
      fontsize:
        label: Font Size
        type: number

events.yml

label: Events
preview:
  snippet: blocks/events
  css: /assets/css/blocks/events.css
fields:
  eventlist: # The Builder Field can even be nested!
    type: builder
    label: Event List
    columns: 2
    fieldsets:
      event:
        label: Event
        fields:
          title:
            label: Title
            type: text
          text:
            label: Description
            type: textarea
          date:
            label: Date
            type: date

img.yml

label: Bild
fields:
  image:
    label: Bild
    type: files
    layout: cards
    cover: true
    multiple: false
  caption:
    label: Caption
    type: textarea
    width: 1/2
  alt:
    label: Alternativer Text
    type: text
    width: 1/2
  links:
    label: Link
    type: url
    width: 1/2
  target:
      label: Link-Ziel
      type: checkboxes
      width: 1/2
      options:
        _blank: Neues Fenster

$block in the above returns null in this case, for whatever reason. To verify, change that code snippet to:

<?php
        foreach($page->mybuilder()->toBuilderBlocks() as $block):
           dump($block);
        endforeach;
?>

Does the template spit out the title (after you changed the code)? Or nothing at all apart from header and footer.

Do you happen to use uppercase in file names anywhere?

Please also check file and folder permissions and ownership on the server.

if i change the code to your snippet an array of my content is shown, Kirby\Cms\StructureObject Object. does that mean anything to you?

i have no uppercase filenames.

my development environment looks like this:
I develop locally,
push into git repository
my Webserver (with plesk) pulls the content from git automatically

files have 644
folders 755

I’m sorry,
i just saw that the output with your sippet on my local machine starts like this:

Kirby\Cms\StructureObject Object
(
    [content:protected] => Array
        (
            [sectionfields] => Array
                (
                    [0] => Array
                        (
                            [text] => rem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. **Nulla consequat massa quis** enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Pha
                            [fontfamily] => 
                            [fontsize] => 
                            [_key] => bodytext
                            [_uid] => bodytext_1600095607596_715
                        )

                    [1] => Array
                        (
                            [image] => Array

and remote so:

- 
  sectionfields:
    - 
      text: 'rem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. **Nulla consequat massa quis** enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Pha'
      fontfamily: ""
      fontsize: null
      _key: bodytext
      _uid: bodytext_1600095607596_715
    - 
      image:
        - jason-briscoe-amlfrl8lgls-unsplash.jpg
      caption: ""
      alt: ""
      links: ""
      target: ""
      _key: img
      _uid: img_1600096151679_139

is there anything missing because it starts completly different?

Is that really the snippet that is causing the error? I noticed you are using a nested builder field…

The content looks ok to me.

i am not sure. on my local machine everything works, on the computer of an employee and on the remote web-server it causes this error.

Oh, I didn’t read clossly, so on the remote server, the output is really that string instead of the structure object.

Is the page builder plugin actually present on the server? If it was, then you should see the same as on the local server.

Maybe you added the plugin as a submodule and did not initialize it on the server?

oh no! the plugin folder is completly missing! :woozy_face:
how could this happen? there is no entry in the gitignore file.

As I wrote above, if you have a git submodule workflow or using composer, then it’s probably not in your repo and doesn’t get deployed.

1 Like

thank you very much!
i hope we will be on a good way to develop our site in kirby. it is really fun to develop with this “Tool”.