Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Templates

Bastian Allgeier edited this page Aug 6, 2019 · 5 revisions

The editor stores its content as JSON. To convert it to HTML you can use the blocks field method in your templates.

<?= $page->text()->blocks() ?>

This will create the HTML defined in each block snippet.

Block collection

The blocks field method returns a Blocks collection, which can either be converted to HTML by simply echoing it (see above) or it can be used to inspect blocks individually and loop through them. The Blocks collection has the same methods as all other Kirby collections, like first, last, nth, sortBy, filterBy, limit, offset etc.

<?php foreach ($page->text()->blocks() as $block): ?>
<!-- create some custom HTML for each block -->
<?php endforeach ?>

Read more …

Block object

Each block in the Blocks collection is a Block object, which has a set of methods you can use in your template or custom block snippets.

Read more…

Clone this wiki locally