Skip to content

Kirby 6.0.0

push()

Pushes content to a stack or starts capturing output

push(string $name, Stringable|string|null $content = null, bool $unique = false): void

Parameters

Name Type Default
$namerequired string no default value
$content Stringableorstringornull null
$unique bool false

Examples

Wrap output in push() and endpush() to add it to a stack. It is rendered wherever you call stack() with the same name, no matter whether that happens before or after the push:

/site/snippets/blocks/gallery.php
<?php push('head') ?>
<link rel="stylesheet" href="<?= url('assets/css/gallery.css') ?>">
<?php endpush() ?>

For short content, pass it as second argument:

<?php push('head', '<meta name="robots" content="noindex">') ?>

Push only once

With unique: true, identical content is only added once, even if the snippet is rendered several times:

<?php push('head', css('assets/css/gallery.css'), unique: true) ?>

Read more in the template stacks guide.