So I want to add a sidebar to a page and I can’t pull it off.
I don’t really want to use a snippet, because that sidebar will only live on that 1 page. Also I want users to be able to add content to that sidebar (mostly external URLS) from the panel and from that panel page, not from an extra “sidebar” panel page.
The Page the sidebar has to go in is a collection page, quite like a blog. Its blueprint is like this:
title: PBeFG
sortBy: date desc
columns:
left:
width: 1/2
sections:
info:
type: info
label: Hinweis
text: Füge eine neue Seite hinzu und erstelle einen Entwurf Deines Beitrags.
drafts:
type: pages
templates:
- pbefg-artikel
headline: Entwürfe
status: draft
unlisted:
type: pages
headline: In Arbeit
status: unlisted
right:
width: 1/2
sections:
listed:
type: pages
headline: Veröffentlicht
status: listed
options:
changeTitle: false
changeStatus: false
delete: false
changeSlug: false
drafts: true
duplicate: false
Where ever I try to add a field to this blueprint to add content für that sidebar I get an error.
Is it not possible to add fields to such a blueprint?
And of course I can’t write the php in the template.
I looked at the docs and followed the recipe for structure fields and did this:
<?php
// using the `toStructure()` method, we create a structure collection
$items = $page->linklist()->toStructure();
// we can then loop through the entries and render the individual fields
foreach ($items as $item): ?>
<ul class="pbefg-link-list">
<h2><?= $item->title()->html() ?></h2>
<p><?= $item->text()->html() ?></p>
<li><a href="<?= $item->url() ?>">sidebar-link</a></li>
</ul>
<?php endforeach ?>
</aside>
This leads to an empty aside. No links, no h2, no nothing.
I probably have the wrong variables and the wrong loop and everything, but I can’t figure it out.
Yes they seem fine to work in the blueprint. Here it is:
title: PBeFG
sortBy: date desc
columns:
left:
width: 1/2
sections:
info:
type: info
label: Hinweis
text: |
Füge eine neue Seite hinzu und erstelle einen Entwurf Deines Beitrags.
Unten kannst Du Links zum Thema einfügen.
drafts:
type: pages
templates:
- pbefg-artikel
headline: Entwürfe
status: draft
unlisted:
type: pages
headline: In Arbeit
status: unlisted
right:
width: 1/2
sections:
listed:
type: pages
headline: Veröffentlicht
status: listed
fields:
linklist:
label: Links
type: structure
fields:
titel:
label: Titel
type: text
beschreibung:
label: Beschreibung
type: text
url:
label: URL
type: url
# Verhindern, dass diese Seiten gelöscht, umbenannt oder ihr Status verändert wird
# ChangeStatus ist hier noch auskommentiert, das würde ich dann später ändern
options:
changeTitle: false
changeStatus: false
delete: false
changeSlug: false
drafts: true
duplicate: false
But youur indentation is wrong and this blueprint doesn’t create a structure field but just three separate fields. Depending on whether this field should be in its own column or also in the right column, you have to change this, for example:
title: PBeFG
sortBy: date desc
# Verhindern, dass diese Seiten gelöscht, umbenannt oder ihr Status verändert wird
# ChangeStatus ist hier noch auskommentiert, das würde ich dann später ändern
options:
changeTitle: false
changeStatus: false
delete: false
changeSlug: false
drafts: true
duplicate: false
columns:
left:
width: 1/2
sections:
info:
type: info
label: Hinweis
text: |
Füge eine neue Seite hinzu und erstelle einen Entwurf Deines Beitrags.
Unten kannst Du Links zum Thema einfügen.
drafts:
type: pages
templates:
- pbefg-artikel
headline: Entwürfe
status: draft
unlisted:
type: pages
headline: In Arbeit
status: unlisted
right:
width: 1/2
sections:
listed:
type: pages
headline: Veröffentlicht
status: listed
fieldsection: # start a new fields section here with the same indent level as the `listed` section
type: fields
fields:
linklist:
label: Links
type: structure
fields:
titel:
label: Titel
type: text
beschreibung:
label: Beschreibung
type: text
url:
label: URL
type: url
At first I also didn’t know if I was to make 1 loop for the whole ul element or if I was supposed to make a loop for every element. I did that first (of course, `cause people like me always try the wrong thing first) and that kinda worked. But then I did 1 loop to for all, like above, and that worked much better.
Anyway this thing works now and I thank you so much once again!!!
Sorry for replying late. That actually caught my eye the minute I went to wash the dishes and I realised that those key words are not given, but I have to make them up and fit. I didn’t know that… So I had an aha moment as I was scrubbing a pot.