tearoom1 / kirby-block-reference
Kirby plugin to reference blocks in other pages
Package info
github.com/tearoom1/kirby-block-reference
Type:kirby-plugin
pkg:composer/tearoom1/kirby-block-reference
Requires
- php: ~8.3.0 || ~8.4.0 || ~8.5.0 || ~8.6.0
- getkirby/composer-installer: ^1.1
Requires (Dev)
- getkirby/cms: ^6.0
- phpunit/phpunit: ^11.0
Suggests
None
Provides
None
Conflicts
- getkirby/cms: <6.0
Replaces
None
README
This plugin allows you to reference other blocks. Thus, you can easily repeat a block in multiple places on your page while being able to update it in one central place.
Requirements
| Kirby | Plugin version | Branch |
|---|---|---|
| 6 | 2.x (since 2.0.0) | main |
| 4 and 5 | 1.x (bug fixes only, latest 1.1.1) | kirby-5 |
PHP 8.3 or newer.
Upgrading from version 1
-
Update Kirby and the plugin together: Kirby 6 rejects the way version 1 registers its field, and version 2 does not run on Kirby 4 and 5. With Composer, change both in one command:
composer require getkirby/cms:^6.0 tearoom1/kirby-block-reference:^2.0 --with-all-dependencies
Without Composer, replace the
kirbyfolder and the plugin folder in the same step. -
Blueprints and content stay as they are: the block
referenceand the fieldtype: blockReferencework as before. -
The API routes
getAllPagesandblocksare gone. Custom code that calls them must useblock-reference/pagesandblock-reference/blocks.
Getting started
Use one of the following methods to install & use tearoom1/kirby-block-reference:
Git submodule
If you know your way around Git, you can download this plugin as a submodule:
git submodule add https://github.com/tearoom1/kirby-block-reference.git site/plugins/kirby-block-reference
Composer
composer require tearoom1/kirby-block-reference
Clone or download
- Clone or download this repository from github: https://github.com/tearoom1/kirby-block-reference.git
- Unzip / Move the folder to
site/plugins.
Usage
Use the block by adding it to you blueprints fieldsets if they are defined:
fieldsets: - reference
Drafts
Blocks of draft pages are only rendered for logged-in users, so a reference to a block on an unpublished page does not show it to visitors. Versions before 1.1 rendered them for everyone; to keep that behaviour:
// site/config/config.php 'tearoom1.kirby-block-reference.renderDrafts' => true,
Access Control
The plugin exposes two API routes that the panel block UI uses to look up reference targets: block-reference/pages (list page IDs) and block-reference/blocks (return the blocks of a given page, including drafts). Both routes require a logged-in panel user; they return 401 Unauthorized for anonymous callers.
By default, only admins can use the reference picker. Non-admin roles can be allowed explicitly:
// site/config/config.php 'tearoom1.kirby-block-reference.allowedRoles' => [ 'editor', ],
The page picker and API routes also check Kirby's page read permission for every target page. Users only see pages they are allowed to read.
Developers
The plugin's functions live in TearoomOne\BlockReference\BlockReference (blocksFromPage(), canAccess(), canReadPage(), render()). The global helpers of earlier versions (getBlocksFromPage(), blockReferenceCanAccess(), blockReferenceCanReadPage()) still exist as deprecated wrappers.
Tests: composer install && composer test
Panel bundle: pnpm install && pnpm build (kirbyup)
Support
Block Reference is free and MIT licensed, and it stays that way. If it saves you time, you can help keep it maintained. Paying is voluntary and any amount is welcome.
Agencies and companies that need an invoice can get a Supporter License. You choose the price and whether it covers one project or your whole company. Lemon Squeezy handles the sale as merchant of record, so you get a proper invoice with VAT. The license adds no features and no priority support.
License
This plugin is licensed under the MIT License
Credits
- Developed by Mathis Koblin
Screenshots
Screenshots use sample content at 1408 × 902 pixels. Panel views are cropped to the content area. The main image uses the light theme.
| View | Light | Dark |
|---|---|---|
| Overview | Light | Dark |
