This repository has been archived by the owner on Feb 11, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 28
Block collection
Bastian Allgeier edited this page Aug 6, 2019
·
2 revisions
The blocks
field method returns a Blocks
collection. This is a typical Kirby collection object (comparable to Pages, Files, Users etc.) with all available Block objects.
If you want to get the HTML for all blocks in the collection you can use the html
method or convert the collection to a string
<?= $page->text()->blocks() ?>
… or …
<?= $page->text()->blocks()->html() ?>
<?php foreach ($page->text()->blocks() as $block): ?>
<!-- create some custom HTML for each block -->
<?php endforeach ?>
Returns the number of blocks
<?php if ($page->text()->blocks()->count()): ?>
<div class="blocks">
<?= $page->text()->blocks() ?>
</div>
<?php endif ?>
Filters the collection by the given arguments
<?= $page->text()->blocks()->filterBy('type', 'h1') ?>
Returns the first block
Renders all blocks
Returns the last block
Returns a limited number of blocks
Returns the block at the given index
Returns the collection, starting at the given offset
Returns a subset of all blocks
Converts all blocks to simple arrays