I’m wondering if it’s possible to access individual images from other pages.
Currently I have a blueprint that looks like this.
fields:
text:
label: Description
type: textarea
size: medium
sections:
type: structure
columns:
intro:
width: 1/4
images:
width: 1/2
fields:
intro:
type: text
paragraph:
type: textarea
image:
extends: sections/albums
query: site.pages("post-images").children
I can see the ‘albums’ in the structure but I can drill down to each individual image. Only the group. Is there any way around this?
Somehow that image
field in the blueprint looks wrong. You want to define a field but are extending a section?
Also, you are querying pages here, not files. You would have to set up a files field
image:
type: files
query: site.find("post-images").children.images
That will give you a flat list of images of all children.
Awesome! For some reason it didn’t work but now it is working. Possibly an issue with xampp.
New issue I have is I want to use 2 different styles for my image captions.
I created a select for my images with values ‘left’ and ‘bottom’.
The select is called ‘align’ in my yml file.
<?php if ($section->postimage()->tofile()->align('left')) : ?>
<div class="post-image-right"> <?= $section->postimage()->tofile() ?> </div>
<figcaption class="caption-left">
<span class="caption-bold"><?= $section->postimage()->tofile()->letter() ?> | </span>
<?= $section->postimage()->tofile()->caption() ?>
</figcaption>
</div>
<?php elseif ($section->postimage()->tofile()->align('bottom')) : ?>
<div class="post-image"> <?= $section->postimage()->tofile() ?> </div>
<figcaption class="caption">
<span class="caption-bold"><?= $section->postimage()->tofile()->letter() ?> | </span>
<?= $section->postimage()->tofile()->caption() ?>
</figcaption>
</div>
<?php endif ?>
But it’s not recognizing the different values.
Thanks!
That code somehow doesn’t make sense to me. Could you please post the relevant blueprints to get the references right?
Are letter
and align
fields in a file blueprint?
Yes this is the blueprint for the image that I am referencing.
title: Image
columns:
- width: 1/2
sections:
content:
type: fields
fields:
caption:
label: Caption
type: textarea
size: medium
- width: 1/2
sections:
meta:
type: fields
fields:
alt:
label: Alternative Text
type: text
letter:
type: select
width: 1/3
options:
- A
- B
- C
- D
- E
align:
type: select
width: 1/3
options:
- left
- bottom
link:
label: Link
type: url
<?php if ($image = $section->postimage()->tofile()) :?>
<div class="post-image<?= $image->align()->value() === 'right'? '-right' . '' ?>">
<?= $image ?>
<figcaption class="caption-left">
<span class="caption-bold"><?= $image->letter() ?> | </span>
<?= $image->caption() ?>
</figcaption>
</div>
<?php endif ?>
But I’m missing the figure tag here as parent of the figcaption.