# Plugin for an extended structure field with more than one kind of field set

**URL:** <https://forum.getkirby.com/t/plugin-for-an-extended-structure-field-with-more-than-one-kind-of-field-set/1696>\
**Category:** Plugins\
**Created:** [July 27, 2015, 4:21pm UTC](https://forum.getkirby.com/t/plugin-for-an-extended-structure-field-with-more-than-one-kind-of-field-set/1696 "2015-07-27T16:21:43Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![timoetting](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/timoetting/32/781_2.png) [@timoetting](https://forum.getkirby.com/u/timoetting)\
**Post date:** [July 27, 2015, 4:21pm UTC](https://forum.getkirby.com/t/plugin-for-an-extended-structure-field-with-more-than-one-kind-of-field-set/1696/1 "2015-07-27T16:21:43Z")

</div>

Hey,

Following the [discussion on how a page builder in Kirby could look like](http://forum.getkirby.com/t/choose-from-multiple-field-groups-within-a-structure-field/1296) I made this little builder plugin. It is an extended structure field with the possibility to add more then one kind of field set.

The plugin also comes with the handy placeholder variable _\_fileUrl_ that can be used inside your entry templates of the blueprint to get thumbnails in your structure panels.

Have a look in the plugin’s github page: [https://github.com/TimOetting/kirby-builder](https://github.com/TimOetting/kirby-builder)

Here is a blueprint example:

```
fields:
  ...
  builder:
    label: Sections
    type: builder
    fieldsets:
      bodytext:
        label: Body Text
        fields:
          text:
            label: text
            type: textarea
      linkedImage:
        label: Linked Image
        entry: >
          <img src="{{_fileUrl}}{{image}}" height=120px/></br>
          {{url}}
        fields:
          image:
            label: Category
            type: select
            options: images
          url:
            label: Link Url
            type: text
      quote:
        label: Quote
        entry: >
          <i>"{{text}}"</i></br></br>
          {{citation}}
        fields:
          text:
            label: Quote Text
            type: textarea
          citation:
            label: Citation
            type: text

```

This will give us a section field like this:

![Kirby builder Screenshot](https://raw.githubusercontent.com/TimOetting/kirby-builder/master/PREVIEW.gif)

The content will be stored like this:

```
----

Builder: 

- 
  text: >
    Lorem ipsum dolor sit amet, consectetur
    adipisicing elit. Ipsa, rerum quam
    similique numquam doloremque, quidem
    sequi placeat quibusdam aspernatur
    doloribus tempore, obcaecati eligendi
    odio eaque repellendus accusamus veniam
    blanditiis impedit.
  _fieldset: bodytext
- 
  image: forrest.jpg
  url: www.getkirby.com
  _fieldset: linkedImage
- 
  text: >
    Power is of two kinds. One is obtained
    by the fear of punishment and the other
    by acts of love. Power based on love is
    a thousand times more effective and
    permanent then the one derived from fear
    of punishment.
  citation: Mahadma Gandhi
  _fieldset: quote
```

---

<div class="post-metadata">

**Author:** ![iancox](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/iancox/32/9529_2.png) [@iancox](https://forum.getkirby.com/u/iancox)\
**Post date:** [July 27, 2015, 5:04pm UTC](https://forum.getkirby.com/t/plugin-for-an-extended-structure-field-with-more-than-one-kind-of-field-set/1696/2 "2015-07-27T17:04:50Z")

</div>

This looks great! It seems to be exactly what I was hoping for in that previous thread. Can’t wait to try this out.

---

<div class="post-metadata">

**Author:** ![A\_Monkey](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/a_monkey/32/413_2.png) [@A\_Monkey](https://forum.getkirby.com/u/A_Monkey)\
**Post date:** [July 28, 2015, 11:49am UTC](https://forum.getkirby.com/t/plugin-for-an-extended-structure-field-with-more-than-one-kind-of-field-set/1696/3 "2015-07-28T11:49:05Z")

</div>

This is probably the most epic plugin i have seen so far, big thanks for sharing @timoetting !!!  
Takes Kirby to another dimension !

@bastianallgeier you should really have a look…

---

<div class="post-metadata">

**Author:** ![jenstornell](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jenstornell/32/546_2.png) [@jenstornell](https://forum.getkirby.com/u/jenstornell)\
**Post date:** [July 28, 2015, 12:15pm UTC](https://forum.getkirby.com/t/plugin-for-an-extended-structure-field-with-more-than-one-kind-of-field-set/1696/4 "2015-07-28T12:15:24Z")

</div>

Is this what inspired you to do this? It looks alot like it.

> **[ACF | Flexible Content Field](https://www.advancedcustomfields.com/add-ons/flexible-content-field/)**
>
> The Flexible content field acts as a blank canvas to which you can add an unlimited number of layouts with full control over the order.

  

> **[ACF | Flexible Content](https://www.advancedcustomfields.com/resources/flexible-content/)**
>
> Description The Flexible Content field provides a simple, structured, block-based editor. Using layouts and sub fields to design the available blocks,

Nice work anyway.

---

<div class="post-metadata">

**Author:** ![timoetting](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/timoetting/32/781_2.png) [@timoetting](https://forum.getkirby.com/u/timoetting)\
**Post date:** [July 28, 2015, 5:59pm UTC](https://forum.getkirby.com/t/plugin-for-an-extended-structure-field-with-more-than-one-kind-of-field-set/1696/5 "2015-07-28T17:59:40Z")

</div>

@jenstornell yes, I worked with the advanced custom fields plugin for wordpress a while ago. I think this has also been the initial motivation iancox’s topic I mentioned in my original post.

However, the idea of a page builder is quite common amongst modern cms, especially those hosted solutions like wix or squarespace. So, I can’t really tell you where my “inspiration” came from. I just needed it for a project And this solution was the most obvious one 😄

@A_Monkey thanks for the epic words 😉

---

<div class="post-metadata">

**Author:** ![tobiasweh](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/tobiasweh/32/13376_2.png) [@tobiasweh](https://forum.getkirby.com/u/tobiasweh)\
**Post date:** [July 30, 2015, 11:22am UTC](https://forum.getkirby.com/t/plugin-for-an-extended-structure-field-with-more-than-one-kind-of-field-set/1696/6 "2015-07-30T11:22:36Z")

</div>

Thanks! That’s a great plugin coming just in time for my new blog. This is how I access the content in my panel:

```auto
<?php switch ($block->_fieldset()):
   case 'text': ?>
        <div class="text"><?php echo $block->text()->kt() ?></div>
    <?php break; ?>
    <?php case 'code': ?>
        <div class="wide-code"><pre><?php echo $block->code()->syntaxHighlighter($block->syntax()) ?></pre></div>
    <?php break; ?>
    <?php case 'codeandtext': ?>
        <div class="comment"><?php echo $block->text()->kt() ?></div>
        <div class="code"><pre><?php echo $block->code()->syntaxHighlighter($block->syntax()) ?></pre></div>
    <?php break; ?>
    <?php case 'codeandtextwide': ?>
        <div class="wide-comment"><?php echo $block->text()->kt() ?></div>
        <div class="wide-code"><pre><?php echo $block->code()->syntaxHighlighter($block->syntax()) ?></pre></div>
    <?php break; ?>
    <?php default: ?>
        <div class="text"><?php echo $block->text()->kt() ?></div>
<?php endswitch ?>

```

@timoetting: Maybe you like to add such an example to the read me file for the less experienced users …

---

<div class="post-metadata">

**Author:** ![timoetting](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/timoetting/32/781_2.png) [@timoetting](https://forum.getkirby.com/u/timoetting)\
**Post date:** [July 30, 2015, 3:42pm UTC](https://forum.getkirby.com/t/plugin-for-an-extended-structure-field-with-more-than-one-kind-of-field-set/1696/7 "2015-07-30T15:42:41Z")

</div>

Happy to hear from you that the plugin is already in use.

You could also consider to utilize snippets for the different section types to get a more clean code. This could then look like this:

###site/snippets/sections/text.php

```auto
<div class="text"><?php echo $block->text()->kt() ?></div>

```

###site/snippets/sections/codeandtext.php

```auto
<div class="comment"><?php echo $block->text()->kt() ?></div>
<div class="code"><pre><?php echo $block->code()->syntaxHighlighter($block->syntax()) ?></pre></div>

```

###site/snippets/sections/codeandtextwide.php

```auto
<div class="wide-comment"><?php echo $block->text()->kt() ?></div>
<div class="wide-code"><pre><?php echo $block->code()->syntaxHighlighter($block->syntax()) ?></pre></div>

```

###The Template

```auto
<?php
    ...
    snippet( 'sections/' . $block->_fieldset(), array('block' => $block) )
    ...
?>

```

I will get an example into my readme soon. Thanks for the suggestion.

---

<div class="post-metadata">

**Author:** ![flokosiol](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/flokosiol/32/468_2.png) [@flokosiol](https://forum.getkirby.com/u/flokosiol)\
**Post date:** [July 30, 2015, 4:00pm UTC](https://forum.getkirby.com/t/plugin-for-an-extended-structure-field-with-more-than-one-kind-of-field-set/1696/8 "2015-07-30T16:00:56Z")

</div>

Great job @timoetting! This is a topic which was discussed a lot here in the forum. Can’t wait to try it out.

Nevertheless, I have one suggestion: It would be awesome to have the opportunity to hide a fieldset temporarily. So a third button „hide“ (beside „edit“ and „delete“) would be fantastic. For the moment it’s possible to add a checkbox „hide me“ to each fieldset and to check for this, but a native solution would be awesome 😉

---

<div class="post-metadata">

**Author:** ![tobiasweh](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/tobiasweh/32/13376_2.png) [@tobiasweh](https://forum.getkirby.com/u/tobiasweh)\
**Post date:** [July 30, 2015, 5:15pm UTC](https://forum.getkirby.com/t/plugin-for-an-extended-structure-field-with-more-than-one-kind-of-field-set/1696/9 "2015-07-30T17:15:18Z")

</div>

@timoetting: Wow – that’s cool. I didn’t know that I can use snippets in that way 🙂

---

<div class="post-metadata">

**Author:** ![AhoyLemon](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/ahoylemon/32/4762_2.png) [@AhoyLemon](https://forum.getkirby.com/u/AhoyLemon)\
**Post date:** [August 2, 2015, 6:13pm UTC](https://forum.getkirby.com/t/plugin-for-an-extended-structure-field-with-more-than-one-kind-of-field-set/1696/10 "2015-08-02T18:13:11Z")

</div>

Hey @timoetting.

Is the install process more than just putting the /plugin and /builder files in there and then modifying the blueprint?

I just tried to get started by copying those two folders and then copied the `builder:` structure from your [GitHub Repo](https://github.com/TimOetting/kirby-builder) into an existing blueprint, and I get this…

![](https://europe1.discourse-cdn.com/flex017/uploads/getkirby/original/1X/020e1518c8afcdb047ce4c24d4c76e9222480fa1.png)

---

<div class="post-metadata">

**Author:** ![timoetting](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/timoetting/32/781_2.png) [@timoetting](https://forum.getkirby.com/u/timoetting)\
**Post date:** [August 3, 2015, 12:25am UTC](https://forum.getkirby.com/t/plugin-for-an-extended-structure-field-with-more-than-one-kind-of-field-set/1696/11 "2015-08-03T00:25:51Z")

</div>

Hey AhoyLemon,

yes, the install process only requires you to put the content of the two folders from the github repo into `site/fields/builder/`and `site/plugins/builder/` and to add your builder fields to the blueprints. I’m not exactly sure if you really refer to the right folders by writing _“/plugin and /builder”_ 😉 .

Following these steps the Extension should be up and running. I just rechecked this process and could not reproduce your error. Did you try to get it running on a new Kirby installation?

On what exact page did this error occur? Is it every page in the panel or just the particular one that is affected by the plugin? Do you have to perform a specific action to get this error (e.g. adding a new field)? And do you have other plugins running on your site?

I hope we can figure this out.

---

<div class="post-metadata">

**Author:** ![timoetting](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/timoetting/32/781_2.png) [@timoetting](https://forum.getkirby.com/u/timoetting)\
**Post date:** [August 3, 2015, 12:51am UTC](https://forum.getkirby.com/t/plugin-for-an-extended-structure-field-with-more-than-one-kind-of-field-set/1696/12 "2015-08-03T00:51:25Z")

</div>

> [@flokosiol](#):
>
> So a third button „hide“ (beside „edit“ and „delete“) would be fantastic. For the moment it’s possible to add a checkbox „hide me“ to each fieldset and to check for this, but a native solution would be awesome wink

Thanks for the suggestion. However, I try to consider carefully whether the need for additional interface elements is more relevant than remaining with given patterns from the original structure field. I think your custom solution with a “hide me” checkbox is a really good way to accomplish the scenario of temporarily hiding sections. This is why I’m not sure if this would make so much sense to add natively.

Best,  
Tim

---

<div class="post-metadata">

**Author:** ![AhoyLemon](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/ahoylemon/32/4762_2.png) [@AhoyLemon](https://forum.getkirby.com/u/AhoyLemon)\
**Post date:** [August 3, 2015, 1:49am UTC](https://forum.getkirby.com/t/plugin-for-an-extended-structure-field-with-more-than-one-kind-of-field-set/1696/13 "2015-08-03T01:49:21Z")

</div>

Hey Tim,

It’s an existing Kirby installation. I’ve copied over `~/site/fields/builder` and `~/site/plugins/builder` into their appropriate directories. Then I took an existing template (in this case it’s called `hopper.php`) and copy/pasted the structure from the repo just to try to give myself a starting point to work with.

It starts out looking like it’s going to work, but then when I try to select something from the “Add” dropdown, I get the error screenshotted above.

[Here is a gist](https://gist.github.com/AhoyLemon/88650cb2d9393de81d57) of the `hopper.php` that’s giving me an issue right now.

I’m going to try to start a new blueprint just to see if the issue is that I’m starting with a blueprint that has previously existed.

PS: Cache is currently set to false while I try to get this figured out.

---

<div class="post-metadata">

**Author:** ![AhoyLemon](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/ahoylemon/32/4762_2.png) [@AhoyLemon](https://forum.getkirby.com/u/AhoyLemon)\
**Post date:** [August 3, 2015, 2:00am UTC](https://forum.getkirby.com/t/plugin-for-an-extended-structure-field-with-more-than-one-kind-of-field-set/1696/14 "2015-08-03T02:00:11Z")

</div>

**Update** : Hmmm, no go. I added a new blueprint to the project using the same structure as [this gist](https://gist.github.com/AhoyLemon/88650cb2d9393de81d57) (but with a different title), and experienced the same results. I could access the page in the panel, but as soon as I picked a selection (any of the 3) from the “Add” menu, I get the PHP error alert box.

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [August 3, 2015, 6:14am UTC](https://forum.getkirby.com/t/plugin-for-an-extended-structure-field-with-more-than-one-kind-of-field-set/1696/15 "2015-08-03T06:14:55Z")

</div>

I just tested your blueprint from the gist and do not get any errors. To me this sounds like the folders are not in the correct location, and since the field does appear, I would guess, it’s a problem of the plugins folder.

---

<div class="post-metadata">

**Author:** ![flokosiol](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/flokosiol/32/468_2.png) [@flokosiol](https://forum.getkirby.com/u/flokosiol)\
**Post date:** [August 3, 2015, 7:18am UTC](https://forum.getkirby.com/t/plugin-for-an-extended-structure-field-with-more-than-one-kind-of-field-set/1696/16 "2015-08-03T07:18:16Z")

</div>

@timoetting Thanks for your reply. I tested your plugin and it’s really awesome!

@AhoyLemon What’s your php-Version? I tried the plugin on an older machine with php 5.3.x and it doesn’t work. But e.g. with php 5.5.x everything runs fine …

---

<div class="post-metadata">

**Author:** ![AhoyLemon](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/ahoylemon/32/4762_2.png) [@AhoyLemon](https://forum.getkirby.com/u/AhoyLemon)\
**Post date:** [August 3, 2015, 6:13pm UTC](https://forum.getkirby.com/t/plugin-for-an-extended-structure-field-with-more-than-one-kind-of-field-set/1696/17 "2015-08-03T18:13:02Z")

</div>

Hey @flokosiol,

Yeah, that’s totally the problem. Just checked, and it turns out the server is currently running v.5.3.10. So I’ll have to get that taken care of first.

Thanks for the direction, I’ll let you know how it goes after updating (which might not be for a couple days)

---

<div class="post-metadata">

**Author:** ![timoetting](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/timoetting/32/781_2.png) [@timoetting](https://forum.getkirby.com/u/timoetting)\
**Post date:** [August 3, 2015, 6:38pm UTC](https://forum.getkirby.com/t/plugin-for-an-extended-structure-field-with-more-than-one-kind-of-field-set/1696/18 "2015-08-03T18:38:46Z")

</div>

Ok, good to know about this issue. I did just test it locally with PHP 5.5. I will have a look on it asap to make it compatible with 5.3.

---

<div class="post-metadata">

**Author:** ![timoetting](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/timoetting/32/781_2.png) [@timoetting](https://forum.getkirby.com/u/timoetting)\
**Post date:** [August 3, 2015, 8:01pm UTC](https://forum.getkirby.com/t/plugin-for-an-extended-structure-field-with-more-than-one-kind-of-field-set/1696/19 "2015-08-03T20:01:03Z")

</div>

I updated the code. It should work now with PHP 5.3

---

<div class="post-metadata">

**Author:** ![AhoyLemon](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/ahoylemon/32/4762_2.png) [@AhoyLemon](https://forum.getkirby.com/u/AhoyLemon)\
**Post date:** [August 4, 2015, 3:44pm UTC](https://forum.getkirby.com/t/plugin-for-an-extended-structure-field-with-more-than-one-kind-of-field-set/1696/20 "2015-08-04T15:44:54Z")

</div>

Oh sweet, thanks @timoetting.

I installed the thing again (still running 5.3.10) and now the panel screen is looking like it should, without that PHP error. I’ll work on hooking in the snippets to pull in the data, but I’m optimistic.

[Next page](https://forum.getkirby.com/t/plugin-for-an-extended-structure-field-with-more-than-one-kind-of-field-set/1696.md?page=2)
