Hi everyone,
I’m building a page structured by full-width lines. Each line is composed of three columns.
I want that when the user create a new line in the panel, it comes with three subpages (wich contents are filling the columns).
I found the guide concerning the subpage builder. I followed each step but my website doesn’t display anything now, the front neither the panel.
Here is my php :
<?php foreach ($page->children() as $line): ?>
<section class="line">
<?php foreach ($line->children() as $block): ?>
<div class="line__container">
<img src="<?= $block->image()->url() ?>" alt="" class="line__container__img">
</div>
<?php endforeach ?>
</section>
<?php endforeach ?>
<footer class="footer">
<nav>
<ul class="menu">
<li class="menu__item">
<a href="#">
<h1>Régulier</h1>
</a>
</li>
</ul>
</nav>
</footer>
First, in my blueprint line.yml, I added :
subpage_builder:
- title: Bloc 1
uid: bloc
template: bloc
num: 1
- title: Bloc 2
uid: bloc
num: 2
template: bloc
- title: Bloc 3
uid: bloc
num: 3
template: bloc
In my config.php, I added the hook :
<?php
return = [
'debug' => true,
'hooks' => [
'page.create:after' => function ($page) {
buildPageTree($page);
}
],
]
I created the files (and the parent folders) /site/plugins/treebuilder/index.php, where I added :
<?php
function buildPageTree($page) {
// get the subpage_builder definition from the blueprint
$builder = $page->blueprint()->subpage_builder();
// if any is set…
if (empty($builder) === false) {
// …loop through each page to be built
foreach($builder as $build) {
// check if all necessary fields have been defined
// in subpage_builder
$missing = A::missing($build, ['title', 'template', 'uid']);
// if any is missing, skip
if (empty($missing) === false) {
continue;
}
try {
// the parent itself is created as a draft
$subPage = $page->createChild([
'content' => [
'title' => $build['title']
],
'slug' => $build['uid'],
'template' => $build['template'],
]);
} catch (Exception $error) {
throw new Exception($error);
}
// publish the subpages, so that they are published
// when the parent is published
if ($subPage) {
// call the function recursively
buildPageTree($subPage);
// publish subpages and sort
$subPage->publish();
if (isset($build['num']) === true) {
$subPage->sort($build['num']);
}
}
}
}
}
Any idea ?
Thanks a lot for your help.