Blueprint processing functions

So I’m developing a plugin that will allow a person to generate a <form> using the standard blueprint structure, but inside a textarea field (so it’s an extension of kirbytext). Let’s say I’ve developed the code to extract the following from the content

Form:
  callback: registration
  success: You rock!
  fields:    	
    fname: 
      label: First Name
      type: text
      required: true
    lname: 
      label: Last Name
      type: text
      required: true
    email:
      label: Email
      type: email
      required: true
    tel:
      label: Phone
      type: tel

My question is this: Is there a function in the Kirby toolkit that can convert the above structure (the structure of blueprints) into an array or object, so I don’t have to write my own parsing function? Because that would turn a 12 hour project into 1.

Have you tried this?

http://getkirby.com/docs/cheatsheet/helpers/yaml

This created an array for me, copy pasted from a blueprint…

$str = '
title: Page
pages: true
files: true
fields:
  title:
    label: Title
    type:  text
  text:
    label: Text
    type:  textarea';
print_r( yaml($str) );

Result

Array
(
    [title] => Page
    [pages] => 1
    [files] => 1
    [fields] => Array
        (
            [title] => Array
                (
                    [label] => Title
                    [type] => text
                )

            [text] => Array
                (
                    [label] => Text
                    [type] => textarea
                )

        )

)

Thanks! I didn’t realize blueprints were YAML. I guess I didn’t even know what YAML was until using Kirby.

Would be great if you could share your results. I’m really interested in this as you can read here :smile:

http://forum.getkirby.com/t/using-blueprints-to-build-frontend-forms/1452

It’s getting somewhere. Have to launch a site this week so I’m not spending a lot of time making sure my code is public-ready, but I’ll throw it in Github soon.

1 Like