Skip to content

Kirby 3.6.6

Layout column methods

Layout column methods are registered with the layoutColumnMethods extension.

Default layout column methods

For a full list of default layout column methods, please check out the Reference.

Be aware that you cannot override these default layout column methods with any custom layout column method.

Getting started

You can extend the set of defined layout column methods in a plugin file.

/site/plugins/layout-column-methods/index.php
Kirby::plugin('my/plugin', [
    'layoutColumnMethods' => [
          'test' => function () {
              return 'layout column method';
          }
      ]
]);

This example shows the basic architecture of a layout column method. You define the method name with the key for the layoutColumnMethods extension array. $this in the callback function refers to the $layoutColumn object.

Working with method arguments

In some cases it might be helpful to be able to pass arguments to the method:

You can define arguments for a method like this:

/site/plugins/layout-column-methods/index.php
Kirby::plugin('my/plugin', [
    'layoutColumnMethods' => [
        'hasBlockType' => function ($type) {
            return $this->blocks()->hasType($type);
        }
    ]
]);

And then use it like this:

<?php $galleryExists = $layout->hasBlockType('gallery') ?>