I’m currently trying to migrate my 3.6.6.1 builder sections to 3.7 blocks (to then proceed to 3.8). I’m having problems updating my templates.
Here’s what I did, following the migration guide:
- replaced ‘builder’ with ‘blocks’ in my blueprint, now:
title: CV
fields:
darkmenu:
label: Dark Menu
type: toggle
title:
label: Title
type: text
description:
label: Description
type: text
darktitle:
label: Dark Title
type: toggle
text: Enabled
blocks:
label: Areas
type: blocks
fieldsets:
empty:
label: ---
snippet: sections/empty
fields:
line:
type: line
area:
label: Area
fields:
headline:
label: Headline
type: text
cvitem:
label: CV Item
fields:
timeframe:
label: Time
type: text
company:
label: Company
type: text
company_additional_information:
label: Company (additional information)
type: text
job:
label: Job
type: text
job_additional_information:
label: Job (additional Information)
type: text
intro:
label: Intro
fields:
initial_letter:
label: Initial
type: text
intro_sentence:
label: Intro Sentence
type: text
text:
label: Text
type: textarea
Updated my content via this (Bulk Builder field to Kirby Block 3.7 conversion - #8 by mactux) PHP script, now my cv.de.txt file contains a big field with the block content:
Iterating over that field in my template works almost well, but not entirely:
This is my main template for blocks-containing pages:
<?php snippet('header'); ?>
<div class="container">
<?php foreach($page->blocks()->toBlocks() as $block): ?>
<?php echo ($block->type()); ?>
<?php snippet('sections/' . $block->type(), ['block' => $block]) ?>
<?php endforeach ?>
<?php if (($kirby->language()->code() == "de") && ($page->slug() == "data-protection")) {
snippet("activities");
snippet("sections/empty");
} ?>
<?= snippet("anchor"); ?>
</div>
<?php snippet('footer'); ?>
And this would be the template - area.php - for the first headline:
<div class="row" style="margin-bottom: 3em;">
<div class="col-sm-4">
</div>
<div class="col-sm-8">
<h2>
<?= $block->headline() ?>
</h2>
</div>
</div>
… and this is where the problem occurs:
Call to undefined method Kirby\Editor\Block::headline()
It seems that the block doesn’t end up in the template as a proper structure.
var_dump($block)
outputs:
object(Kirby\Editor\Block)#430 (8) { ["attrs":protected]=> object(Kirby\Cms\Content)#431 (0) { } ["content":protected]=> object(Kirby\Cms\Field)#432 (1) { ["content"]=> array(1) { ["headline"]=> string(44) "Akademischer und
beruflicher Werdegang " } } ["id":protected]=> string(36) "3bc5d26c-edb4-498f-a7c8-01ef3f547ed2" ["options":protected]=> array(0) { } ["params":protected]=> NULL ["parent":protected]=> object(Kirby\Cms\Page)#308 (15) { ["children"]=> object(Kirby\Cms\Pages)#473 (0) { } ["content"]=> object(Kirby\Cms\Content)#328 (5) { ["title"]=> string(2) "CV" ["darkmenu"]=> string(4) "true" ["description"]=> ...
… so it does seem to have the “Block” class. But it doesn’t have the substructure (->headline()) it should have?
Thanks for any leads
Fabian