Reference

Guide

snippet()

Embeds a snippet from the snippet folder

snippet(string $name, array|object $data = [ ], bool $return = false): string

Parameters

Name Type Default Description
$name string
$data array|object [ ]
$return bool false

Return type

string

Example

// Include the header snippet
<?php snippet('header') ?>

// Set the $class variable inside the snippet to "blog"
<?php snippet('header', ['class' => 'blog']) ?>

// Return the rendered snippet code
<?php $header = snippet('header', [], true);
<?php $header = snippet('header', ['class' => 'blog'], true);

Source code

kirby/config/helpers.php#L677