hananils/kirby-snippetwhen-helper

Helper function for Kirby to embed snippets only when a condition is met.

1.0.1 2021-11-18 13:00 UTC

This package is auto-updated.

Last update: 2024-09-05 15:30:00 UTC


README

Kirby snippetWhen Helper

snippetWhen is a helper function for Kirby 3 to conditionally embed snippets.

Installation

Download

Download and copy this repository to /site/plugins/snippetwhen-helper.

Git submodule

git submodule add https://github.com/hananils/kirby-snippetwhen-helper.git site/plugins/snippetwhen-helper

Composer

composer require hananils/kirby-snippetwhen-helper

Usage

snippetWhen($snippet, $condition, $expected, $data)

Conditionally embeds a snippet:

  • $snippet: the name of the snippet
  • $condition: a condition that either evaluates to true or false
  • $expected: the expected result of the condition, defaults to true
  • $data: data object passed to the snippet
snippetWhen('article', $page->category()->isNotEmpty());

License

This plugin is provided freely under the MIT license by hana+nils · Büro für Gestaltung.
We create visual designs for digital and analog media.