Download the PHP package owebstudio/kirby-template-stacks without Composer
On this page you can find all versions of the php package owebstudio/kirby-template-stacks. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download owebstudio/kirby-template-stacks
More information about owebstudio/kirby-template-stacks
Files in owebstudio/kirby-template-stacks
Package kirby-template-stacks
Short Description Template stacks allows you to push to named stacks which can be rendered somewhere else in another snippet or template.
License MIT
Homepage https://owebstudio.com
Informations about the package kirby-template-stacks
Kirby Template Stacks
[!IMPORTANT] This plugin is in maintenance mode and only gets security fixes. It supports Kirby 3.5 to 5. Kirby 6 has its own
push(),endpush()andstack()helpers, so you don't need this plugin anymore. Remove it before you upgrade to Kirby 6, see Upgrading to Kirby 6.
Template stacks allows you to push to named stacks which can be rendered somewhere else in another snippet or template. This idea is inspired from Laravel Blade Stacks.
Upgrading to Kirby 6
Delete the plugin folder from site/plugins (or run composer remove owebstudio/kirby-template-stacks) before you update Kirby. Your push(), endpush() and stack() calls then use the Kirby 6 helpers. Most templates work without changes, but check these differences:
| Template Stacks | Kirby 6 |
|---|---|
push('scripts', true) |
push('scripts', unique: true) |
stack('scripts', true) |
stack('scripts', return: true) |
| Items are joined without a separator. | Items are joined with a line break. Use stack('scripts', '') to join them without one. |
| A stack keeps its items after it is rendered. | A stack is emptied after it is rendered. Use stack('scripts', clear: false) to render it again. |
A stack in <head> stays empty, because the pushes in the template run after it. |
Stacks can be rendered anywhere, also before the pushes, e.g. in <head>. |
Change the true arguments first. In Kirby 6 the second argument of push() is the content and the second argument of stack() is the glue. So push('scripts', true) adds 1 to the stack and prints the content in place, and stack('scripts', true) prints the items joined with 1 instead of returning them.
Installation
- Download the latest release
- Unzip downloaded file
- Copy/paste unzipped folder in your
/site/pluginsfolder
Methods
stack()
Calls a given stack name and prints all the items in it. The last data is printed last.
push() ... endpush()
Pushes data to a given stack name. The sent data is thrown to the end of the stack.
If the pushed data is unique and in a repeating loop, you can send the secondary parameter as true. For example; if you want a javascript library to be loaded only once in a blocks field.
Samples
Sample 1: with snippets and templates
Defining stacks
/site/snippets/header.php
/site/snippets/footer.php
Pushing contents to the stack
/site/templates/home.php
Sample 2: with new snippets with slots feature
Defining stacks
/site/snippets/layouts/default.php
Pushing contents to the stack
/site/templates/home.php