Hello,
I have made a clickthrough gallery with some simple javascript which works, but I would like to also display the image metadata. I cant seem to get the metadata to update with the src. Iām copying the code here. I imagine there is a simple solution I am missing. Is there a way to get the file based on id - so I could display the metadata of the āfeatured-imageā?
Thank you!
<?php snippet('header') ?> <?php snippet('menu') ?> <?php snippet('mobilemenu') ?><figcaption>
<div>
<h1><?= $page->title() ?></h1>
<h1><?= $page->headline()->or($page->gallery()) ?></h1>
<time class="project-year"><?= $page->year() ?></time>
<?php if ($page->intro()->isNotEmpty()) : ?>
<div class="toptext">
<?= $page->intro()->kt()->lower() ?>
</div>
<?php endif ?>
</div>
</figcaption>
<div class="project-text">
<?= $page->text()->kt()->lower() ?>
<?php if ($page->textTwo()->inNotEmpty()) : ?>
<?= $page->textTwo()->lower() ?>
<?php endif ?>
</div>
<div class="project-cover">
<?php if ($cover = $page->image()) : ?>
<figure class="project-cover">
<img src="<?= $cover->resize(1200, 1000)->url() ?>" alt="<?= $cover->alt() ?>" id="featured-image" />
<div class="credits">
<p> <?php if ($cover->alt()->isNotEmpty()) : ?>
<?= $cover->alt() ?>
<?php endif ?></p>
<p> <?php if ($cover->title()->isNotEmpty()) : ?>
<?= $cover->title() ?>
<?php endif ?></p>
<p> <?php if ($cover->technique()->isNotEmpty()) : ?>
<?= $cover->technique() ?>
<?php endif ?> </p>
<p> <?php if ($cover->year()->isNotEmpty()) : ?>
<?= $cover->year() ?>
<?php endif ?> </p>
<script>
var coverMetadata = {
title: '<?= $cover->title() ?>',
technique: '<?= $cover->technique() ?>',
year: '<?= $cover->year() ?>',
collection: '<?= $cover->collection() ?>'
};
</script>
</div>
</figure>
<?php endif ?>
</div>
<div class="gallery">
<?php if ($gallery = $page->images()->sortBy('sort', 'asc')) : ?>
<ul class="project-gallery">
<?php foreach ($gallery as $index => $image) : ?>
<li
data-title="<?= $image->title() ?>"
data-technique="<?= $image->technique() ?>"
data-year="<?= $image->year() ?>"
data-collection="<?= $image->collection() ?>"
>
<a href="">
<img
src="<?= $image->resize(1200, 1000)->url() ?>"
alt="<?= $image->alt() ?>"
class="gallery-image"
/>
</a>
<div class="credits">
<p> <?php if ($image->alt()->isNotEmpty()) : ?>
<?= $image->alt() ?>
<?php endif ?></p>
<p> <?php if ($image->title()->isNotEmpty()) : ?>
<?= $image->title() ?>
<?php endif ?></p>
<p> <?php if ($image->technique()->isNotEmpty()) : ?>
<?= $image->technique() ?>
<?php endif ?> </p>
<p> <?php if ($image->year()->isNotEmpty()) : ?>
<?= $image->year() ?>
<?php endif ?> </p>
<p> <?php if ($image->collection()->isNotEmpty()) : ?>
<?= $image->collection() ?>
<?php endif ?><p>
</div>
</li>
<?php endforeach ?>
</ul>
<?php endif ?>