Forum
Responsive images in collections and multiple templates
Hey there,
I have a collection called Projects, which has its primary template as project.html. I've set up responsive images using a single image content field, and this works fine in any page pulling in the project.html main template. It's marked up as such:
<picture>
<source
media="(min-width: 990px)"
srcset='<perch:content id="image" type="image" bucket="Project" label="Image" width="800" height="400" crop="true" />'>
<source
media="(min-width: 768px)"
srcset='<perch:content id="image" type="image" bucket="Project" label="Image" width="400" height="250" crop="true" />'>
<source
media="(min-width: 480px)"
srcset='<perch:content id="image" type="image" bucket="Project" label="Image" width="500" height="300" crop="true" />'>
<img
src='<perch:content id="image" type="image" bucket="Project" label="Image" width="350" height="250" crop="true" />'>
</picture>
Now, I pull this collection into multiple templates for different contexts. But when I include the exact snippet as above in any of these other templates, the responsive images don't work. Instead, all the source fields reference the same file with no cropping involved, as such:
<picture>
<source media="(min-width: 990px)" srcset="/perch/resources/Project/header.jpg">
<source media="(min-width: 768px)" srcset="/perch/resources/Project/header.jpg">
<source media="(min-width: 480px)" srcset="/perch/resources/Project/header.jpg">
<img src="/perch/resources/Project/header.jpg">
</picture>
Is there anywhere I'm going wrong here?
Thanks!
If the code is exactly the same there shouldn't be an issue at all. Is it's exactly the same, or just similar?
Edit: I just checked, and it wasn't exactly the same. I'd left off the 'type=image' attribute in the template. Didn't expect that to kill it! I've made sure they're exactly the same now, and it's working flawlessly. Thanks for pointing this idiot in the right direction!
It's exactly the same. I'll post the relevant code for you.
Recent projects layout:
Which loads in project_thumb_primary.html template:
With the output:
And now here's the individual project page:
Which loads the project.html template:
With the output:
All of the images are successfully created in the resources/Project bucket folder.
Thanks for your help on this!