Content within text files can be structured with fields. You can add as many fields to a content file as your content model requires. Each text file can contain its very own set of fields. Together with the flexible folder structure you get a NoSQL-like data store with literally unlimited possibilities.
If you prefer to write your content files in a text editor, you can separate one field from the next with four dashes on a separate line:
Title: An interesting article ---- Date: 2020-03-30 ---- Text: Really interesting content here...
Each field begins with the fieldname and a colon. The content of a field can be a single or multiple lines of text. You can store plain text, HTML, JSON, YAML or anything else which can be written in plain text in a field.
Fields can be added or removed at any time. All fields are instantly available in Kirby's templates.
When you add fields manually, there is no way to validate what you enter into each field.
Before fields are available to be filled by users in the Panel, they need to be defined for each content model. These field definitions are done in blueprints. The Panel comes with many predefined field types that help with structuring your content. Field definitions in the Panel give you full control over what sort of content each field can contain.
A full list of available field types and their options is available in the Reference. There are several plugins with custom field types available.
In general, you are free to name your fields like you want to, but there are two limitations:
- You can only use alphanumeric characters and underscores in field names.
- If you use field names that are also used by native Kirby methods, your field names will conflict with Kirby's existing methods, e.g. if you give your field the name "image", it will conflict with Kirby's
$page->image()method. You can do this, but you will have to call these fields differently in your templates. For details please refer to the template docs.
Field content is accessible in your templates via the field's name:
<?= $page->title()->html() ?> <?= $page->text()->kirbytext() ?> <?= $page->date()->toDate('Y-m-d') ?>
The methods that are chained to the name of the field are field methods that allow you to modify the field content in multiple ways. You can find a full list of available field methods in the Reference.