Get field's type and translate property

Hello!

I’m writing a plugin that needs to export the site content in the base language and pull everything that needs to be translated in a JSON file.

I can loop through $site fields and all of its children’s fields, but I face an issue. I want to exclude fields that have type image, for example, or fields that explicitly have translate set to false.

How would I do that?

I want that information to be accessible via an endpoint, for example http://localhost/mysite/content. This means I’ve configured a route and I need to extract the information in the route handler.

I’ve read Generating JSON with Kirby, but it does a different thing.

Another question needed something similar and perhaps the answer is the same? The difference is that I want to access that information from a route handler and not a site template. Quoting lukasbestle:

If you need that information though, you can manually get the path to the blueprint by using kirby()->roots->blueprints() . DS . $page->template() . '.php' and use Yaml::read() with that filename to parse the blueprint.

Is that the only way?

Information about a field is only available through the data in the blueprint. There are two plugins that allow you to access blueprint data (there is no native way to do that in Kirby 2).

Whether or not you access that data from a template or a route handler doesn’t make any difference.

1 Like

Whether or not you access that data from a template or a route handler doesn’t make any difference.

I don’t believe that’s true. If I try kirby()->roots()->blueprints() in the route handler, it returns nothing. If I do it in a template, it works normally. Is there a way I can make it work in the route handler?

Edit: Actually, none of the roots() methods work in the handler.

Edit 2: Nevermind, I used response::json at the end of the handler and it overwrote my debug info…