Populate select field with a text file?

What’s the best method for populating a blueprint select field with data from a text file? Ideally, I’d just have a text file with a list of values that get parsed by the blueprint.

You can’t do that directly within the blueprint, but you could create your own custom field http://getkirby.com/docs/panel/custom-form-fields that reads the data from the field and returns it. Or go for the data API see changelog http://getkirby.com/changelog/kirby-2-1-0

The data API looks promising, but I can’t get it to work properly.

My blueprint has the follow code:

    label: Category
    type: select
    options: /assets/data/category.json

And the JSON file is…

  'key1' : 'value1',
  'key2' : 'value2'

The select box shows up, but has no options. Any thoughts?

I would have thought that passing a complete URL would do the trick but couldn’t get it to work.

[Edit:] It didn’t work on localhost, but once I copied it to a remote server with a “real” URL, it worked like a charm. Apparently, v::url expects a URL scheme with a domain name, so that http://localhost/kirby/ or whatever, doesn’t work and of course, relative paths won’t work at all.

Even with an absolute URL (http://domain.com/assets/data/category.json) it doesn’t work. In fact, when I do that it gives an error:

Does it say anything in your server error logs which might help to pinpoint the problem? As I said, it works for me after passing a real URL. You are on Kirby 2.1.0, aren’t you?

[Edit:] One more thing: Contrary to the changelog documentation, the key-value pairs need to be enclosed in double quotes instead of single quotes …

 "key1": "value1",
 "key2": "value2" 

OK, I fixed it. Logs showed Kirby was trying to use curl_init(), which I didn’t have installed. Now it works as expected.

Thanks for the help, texnixe.

edit: How do I mark this as “solved?”

Click on the edit button next to the headline of this post and select category “solved”.