Hey everyone,
I have a question. I made a project subpage with several projects elements.
Each project element contains a heading with some text and a swiper slider with multiple images.
How could it be possible to add and remove the entire project element via the panel (heading, text, image slider)?
It’s my first time trying something more complex.
My template code:
<section class="objekt-element">
<div class="objekt-heading">
<h2><?=$page->objekt1_titel()?></h2>
</div>
<div class="objekt-text">
<?=$page->objekt1_text()->kt()?>
</div>
<div class="swiper-container swiper1">
<!-- Additional required wrapper -->
<div class="swiper-wrapper">
<!-- Slides -->
<?php foreach($page->find('gallery_1')->images() as $image): ?>
<div class="swiper-slide"><img class="slide" src="<?php echo $image->resize(1000, 667)->url() ?>"
alt="<?= $image->alt() ?>"></div>
<?php endforeach ?>
</div>
<!-- If we need pagination -->
<div class="swiper-pagination swiper-pagination1"></div>
<!-- If we need navigation buttons -->
<div class="swiper-button-prev"></div>
<div class="swiper-button-next"></div>
</div>
</section>
This code block gets repeated multiple times and i change all names to objekt_2_text and gallery_2 and so on…I know this is a „creative“ solution
My Blueprint:
title: Dienstleistung
columns:
left:
width: 2/3
sections:
content:
type: fields
fields:
info:
label: info
type: info
text: Die Nummerierung, der Elemente ist passend zu der Gallerie auf der rechten Seite. Die Inhalte gehören zusammen. z.b. Objekt 1 Text => Gallerie_1
objekt1_titel:
label: Objekt 1 Titel
type: text
objekt1_text:
label: Objekt 1 Inhalt
type: textarea
objekt2_titel:
label: Objekt 2 Titel
type: text
objekt2_text:
label: Objekt 2 Inhalt
type: textarea
right:
width: 1/3
sections:
files:
type: files
headline: Headerbild
template: image
gallery:
headline: Gallerien
type: pages
layout: cards
max: 5
image:
cover: true
each gallery is a subpage.
If I delete the gallery content in the panel, I get the Call to a member function images() on null error. I know that is because there aren’t any images.
Is ist possible to change the code in the template that it doesn’t matter if there aren’t any images and
if there are any they get displayed?
I have the feeling that my hole approach could be wrong because I´m repeating myself for each element in the template. Because of that I have no chance for dynamic content via the panel. Could it be possible to generate the project elements with multiple structured fields? I’m thankful for every little clue.