Blocks & Layouts

Learn how to generate content for blocks and layout fields.

Kirby Copilot v2.4 introduces a new way to generate blocks that finally supports custom blocks and layout fields. You caould say that Kirby Copilot has become a true page builder for Kirby CMS.

Previously, Copilot could only generate blocks for Kirby's core blocks (heading, text, list, etc.). This was quite limiting, as it meant that any custom blocks defined in your Kirby project could not be generated by the AI.

With the new blocks generation process, Copilot can now generate any block type defined in your Kirby project, including custom blocks. It accomplishes this by using object generation with JSON schemas, which enables the AI to generate structured data that matches the block definitions in your project.

How It Works

Project Block Definitions

Copilot reads the project's block definitions, including those from plugins. If the fieldsets limits the blocks to a specific set, then only those blocks are considered for generation.

JSON Schema

Based on these block definitions, Copilot generates a JSON schema that defines the structure of each block, including nested fields such as structure fields.

Object Generation

The prompt includes the JSON schema, which enforces the AI to respond with structured data that matches the schema.

Response Handling

The AI's response is parsed and normalized to Kirby's block structure, allowing it to be used directly in the CMS.

Please use Google Gemini models, since OpenAI's models have limitations on nested structured outputs. Gemini models have superior structured output capabilities.

Caveats

Depending on the block's complexity, the resulting JSON schema can become equally complex. This leads to the following caveats:

  • Schema size: OpenAI has limitations on the nesting depth and size of JSON schemas. If the schema is too large, the AI will fail to generate a response. In this case, try reducing the number of blocks used in the fieldsets or simplify the block definitions.
  • Layout generation: Due to the same limitations of OpenAI, the layout field generation is only supported by models other than OpenAI. Gemini models are recommended for this feature.