Working with global blocks
The everyday tasks after your first global block
In Getting started, you placed one global block on two pages. This page covers the tasks that come up after that.
Turn an existing block into a global block
- Open a page with an enabled field, open the block's menu, and choose Turn into global block.
- Enter a title and optional description.
- If the block uses files from this page, choose whether to Copy files to the global block. Without a copy, the global block keeps using the files of the page (Files and UUIDs).
- Submit the dialog and click Save.
Clicking Discard before saving deletes the new global block unless another page uses it. If Turn into global block is missing, check Options and create in Permissions.
Layout and nested fields
Add globalBlocks: true to a layout field and render it with $page->layout()->toLayouts():
# site/blueprints/pages/about.yml
fields:
layout:
type: layout
layouts:
- "1/1"
- "1/2, 1/2"
globalBlocks: true
The same option works on blocks fields inside structure, object, or custom block blueprints. Inline block types need a matching site/blueprints/blocks/<name>.yml file before they can become global blocks (Limits).
Detach, hide, copy, and paste a placement
Open a global block's menu on a page and choose Detach from global block to turn it into a normal block, or Hide to hide only that placement, then click Save. Deleting a global block on a page removes only that placement.
Duplicating a global block or pasting it into a field with globalBlocks: true adds another placement. Pasting into a field without globalBlocks: true creates a normal copy.
Delete a global block that is still used
- Open the block in Global blocks, open its settings menu, and choose Delete.
- If it is still used, follow each link in the dialog to remove, detach, or replace each placement (including draft pages and unsaved changes) and save.
- Return to the block and choose Delete again.
Limit editor permissions
Every Panel role can create, edit, and delete global blocks by default. To make global blocks read-only for a role, restrict tobimori.global-blocks in its user blueprint:
# site/blueprints/users/editor.yml
title: Editor
permissions:
tobimori.global-blocks:
access: true
create: false
update: false
delete: false
Set access: false to hide Global blocks while still letting editors place existing blocks from the selector. Core pages permissions also apply (Permissions).
Show previews with your site styles
Create site/templates/global-block-preview.php to style previews in Global blocks, the block selector, and the Preview button:
<?php snippet('header') ?>
<?= $block ?>
<?php snippet('footer') ?>
If your site header crowds preview cards, load only your stylesheet around <?= $block ?>. See Preview template for variables and access rules.
Store uploads on a shared page
A files field inside a global block uploads to that global block by default (Files and UUIDs). To upload to a shared images page instead, set query and uploads.parent:
# site/blueprints/blocks/banner.yml
name: Banner
fields:
image:
type: files
max: 1
query: site.find('images').images
uploads:
parent: site.find('images')
template: image
Uploads from a banner global block then go to images from both Global blocks and inline edits.
To see how references, locks, and file storage behave across pages, continue to How it works.