Hello,
I use Kirby 4.6.1, PHP 8.2.8, Appache Server
I have a problem in my panel on my layouts, but the front is displayed correctly.
I use layouts, I wanted to add the possibility to add custom classes to my elements (text, image, quote, etc).
Since my last corrections, everything is displayed correctly on the front, but in my panel I see my elements on my page builder, but they’re empty and I can’t modify them.
I realized that I was using blocks and layouts.
So I deleted the /blueprints/blocks folder to keep only the layouts.
I have my .yml files in the folders blueprints/fieldsets/image.yml or blueprints/fieldsets/title.yml or blueprints/fieldsets/text.yml.
I also find the same file names in blueprints/layouts/image.yml or blueprints/layouts/text.yml, and so on.
I have a /snippets/blocks/ folder where I find the same files but in .Php and otherwise I just have a /snippets/layouts.php file.
I’m going round in circles and I can’t find my error
I need your help!
Thanks in advance
Here an example file : blueprints/fieldsets/texte.yml :
name: Texte
icon: text
fields:
content:
label: Texte
type: textarea
Here a page blueprints/pages/reference.yml :
title: Référence
icon: 🖼
status:
draft: true
listed: true
tabs:
infos:
label: Informations
icon: text
columns:
- width: 2/3
fields:
cover:
label: Image de couverture
type: files
max: 1
uploads: image
headline:
label: Titre d’accroche
type: text
placeholder: "{{ page.title }}"
help: Laisser vide pour utiliser automatiquement le titre
subheadline:
label: Sous-titre
type: text
text:
label: Texte principal
type: writer
tags:
label: Tags
type: tags
category:
label: Catégorie
type: select
options:
- Marque employeur
- RSE
- Mobilisation
- Transformation
help: Catégorie utilisée pour le tri ou les filtres
- width: 1/3
sections:
images:
label: Galerie d’images
type: files
layout: cards
template: image
info: "{{ file.dimensions }}"
image:
ratio: 5/4
cover: true
min: 1
size: small
content:
label: Contenu structuré
icon: layout
fields:
layout:
label: Mise en page
type: layout
layouts:
- "1/1"
- "1/2, 1/2"
- "1/3, 2/3"
- "2/3, 1/3"
- "1/3, 1/3, 1/3"
- "1/4, 3/4"
- "3/4, 1/4"
- "1/4, 1/4, 1/4, 1/4"
- "1/6, 1/6, 1/6, 1/6, 1/6, 1/6"
fieldsets:
- titre
- texte
- image
- galerie
- citation
- video
- bouton
- liste
- espace
settings:
fields:
gap:
label: Espace entre colonnes
type: select
width: 1/2
default: medium
options:
none: Aucun
small: Petit
medium: Moyen
large: Grand
margin:
label: Marge verticale (haut/bas)
type: select
width: 1/2
default: medium
options:
none: Aucune
small: Petite
medium: Moyenne
large: Grande
seo:
label: SEO
icon: search
columns:
- width: 1/2
fields:
seo_title:
label: Titre SEO
type: text
seo_description:
label: Description SEO
type: textarea
seo_keywords:
label: Mots-clés SEO
type: tags
seo_preview:
label: Aperçu Google
type: info
theme: info
text: >
<div style="font-family:Arial,sans-serif;font-size:14px;line-height:1.4">
<div style="color:#1a0dab;font-size:18px;line-height:1.2;font-weight:normal;">
{{ page.seo_title.or(page.title) }}
</div>
<div style="color:#006621;font-size:14px;">{{ page.url }}</div>
<div style="color:#545454;">
{{ page.seo_description }}
</div>
</div>
- width: 1/2
fields:
seo_image:
label: Image SEO
type: files
max: 1
uploads: image
le fichier snippets/blocks/texte.php :
<?php
$style = '';
if ($block->margin()->isNotEmpty()) {
$style .= 'margin:' . $block->margin()->value() . ';';
}
if ($block->padding()->isNotEmpty()) {
$style .= 'padding:' . $block->padding()->value() . ';';
}
$class = 'bloc-texte';
if ($block->classe()->isNotEmpty()) {
$class .= ' ' . $block->classe()->esc();
}
?>
<div class="<?= $class ?>" style="<?= $style ?>">
<?= kirbytext($block->texte()) ?>
</div>
here my file : snippets/layouts.php :
<?php
// Génère les classes CSS pour le layout (ex: "layout-1_2-1_2 gap-medium margin-large")
function layoutClass($layout) {
$widths = [];
foreach ($layout->columns() as $column) {
$widths[] = str_replace('/', '_', $column->width());
}
$gap = $layout->attrs()->gap()->or('medium'); // Valeur par défaut : medium
$margin = $layout->attrs()->margin()->or('medium');
return 'layout-' . implode('-', $widths) . ' gap-' . $gap . ' margin-' . $margin;
}
?>
<?php foreach ($field->toLayouts() as $layout): ?>
<section
class="layout <?= esc(layoutClass($layout)) ?>"
id="<?= esc($layout->id(), 'attr') ?>"
>
<?php foreach ($layout->columns() as $column): ?>
<div class="layout-column layout-<?= esc(str_replace('/', '_', $column->width())) ?>">
<?= $column->blocks() ?>
</div>
<?php endforeach ?>
</section>
<?php endforeach ?>