9zehn81
February 11, 2019, 9:31am
1
@timoetting s K3 Page Builder is fantastic! I’m creating some different Block-Types, e.g. an image gallery.
But i can’t manage to display all selected files (images) with accessing them as files (in order to use the alt and caption text from the file).
The only way i could display the images yet is:
<?php foreach($data->bilder()->yaml() as $bild): ?>
<div>
<?php if($full = $bild['url']): ?>
<a class="uk-inline" href="<?php echo $full ?>" alt="Alt" data-caption="Caption 1">
<img src="<?php echo $full ?>">
</a>
<?php endif ?>
</div>
<?php endforeach ?>
But this way i cant access the files-meta infos and i cannot even crop them
texnixe
February 11, 2019, 9:43am
2
$data->bilder()->toFiles()
doesn’t work?
If not, please provide your blueprint.
9zehn81
February 11, 2019, 9:49am
3
No, ->toFile() doesn’t work
The blueprint is:
label: Inhaltsblöcke
type: builder
columns: 1
max: 10
fieldsets:
bodytext:
label: Textblock
tabs:
content:
label: Bearbeiten
icon: edit
fields:
text:
label: Text
type: textarea
bildergalerie:
label: Bildergalerie
tabs:
content:
label: Bearbeiten
icon: edit
type: fields
fields:
bilder:
label: Bilder
type: files
einstellungen:
label: Einstellungen
icon: cog
fields:
spalten:
label: Spalten
type: select
options:
drei: 3-spaltig
vier: 4-spaltig
fuenf: 5-spaltig
texnixe
February 11, 2019, 10:40am
4
Hm, ok, this seems to work:
<?php
foreach($data->bilder() as $bild) {
if($img = $page->image($bild['filename'])) {
dump($img);
}
}
?>
Don’t know if this is the best way…
9zehn81
February 11, 2019, 11:05am
5
i tried your snippet right now, but it causes the error “Undefined index: filename”
I figured this out yesterday. ->tofiles()
does work. Something doesn’t feel right about your blueprint. I would double check the structure, the german is confusing me
<?php
$gallery = $data->bilder()->toFiles();
foreach($gallery as $bild): ?>
// Remember to check the image exists...
<img src="<?= $bild->url() ?>">
<?php endforeach ?>
You have probably taken ->yaml()
out an swapped it for ->toFiles()
.
Hey.
I just pushed a new version that fixes some issues with tabs and the files field. It should now work exactly like accesing images from within a structure field
To access images of a builder fieldset you can use something like this:
<?php foreach($data->images()->toFiles() as $image): ?>
<?= $image->resize(100) ?>
<?php endforeach ?>
In the old version, this did only work when not having tabs in the fieldset.
9zehn81
February 12, 2019, 6:08am
8
Yes, great, with the latest update it all works fine! Thank you so much.