I have a matrix block called team that has an assets field within it that has all of the companies headshots. However, there are more than 30 images, but the design is to only have 6 showing on load, and then on click of a load more button the next 6 will show, etc.
However, I'm not sure how to achieve this within a matrix block as all the examples I've seen elsewhere are for pages and sections. But I just need to load the images from within the matrix block.
Below is my code for the images. Can someone help?
{% for headshot in block.headshots %}
<figure class="team__headshots">
{% if headshot | length %}
{% set transformedImages = craft.imager.transformImage(headshot,
[
{ width: 180, ratio: 4/5 },
],
{
format: 'jpg',
allowUpscale: false,
mode: 'crop',
jpegQuality: 80,
position: headshot.focalPoint,
interlace: true
}
) %}
{% set tabletl = craft.imager.transformImage(headshot,
[
{ width: 142, ratio: 4/5 },
],
{
format: 'jpg',
allowUpscale: false,
mode: 'crop',
jpegQuality: 80,
position: headshot.focalPoint,
interlace: true
}
) %}
{% set tabletp = craft.imager.transformImage(headshot,
[
{ width: 230, ratio: 4/5 },
],
{
format: 'jpg',
allowUpscale: false,
mode: 'crop',
jpegQuality: 80,
position: headshot.focalPoint,
interlace: true
}
) %}
{% set mobile = craft.imager.transformImage(headshot,
[
{ width: 360, ratio: 4/5, jpegQuality: 65 },
],
{
format: 'jpg',
allowUpscale: false,
mode: 'crop',
position: headshot.focalPoint,
interlace: true
}
) %}
<picture>
<source srcset="{{ craft.imager.srcset(mobile) }}" media="(max-width: 767px)">
<source srcset="{{ craft.imager.srcset(tabletp) }}" media="(min-width: 768px) and (max-width: 991px)">
<source srcset="{{ craft.imager.srcset(tabletl) }}" media="(min-width: 992px) and (max-width: 1199px)">
<img class="img-responsive"
src="{{ transformedImages[0].url }}"
sizes="(min-width: 768px) 33.3vw, 50vw"
alt="{% if headshot.altTag|length %}{{ headshot.altTag }}{% else %}{{ headshot.title }}{% endif %}"
width="100%">
</picture>
{% endif %}
<div class="team__headshots-overlay">
<div class="team__headshots-captions">
<h4>{{ headshot.title }}</h4>
<p>{{ headshot.jobTitle }}</p>
</div>
</div>
</figure>
{% endfor %}