Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jinja demo of new srcset_image and picture template tags #455

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 133 additions & 0 deletions bakerydemo/jinja2/base/home_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,139 @@ <h2>{{ page.promo_title }}</h2>
</div>
</div>

<div class="container-fluid">
<div class="row">
<div class="col-sm-12">
<h2>srcset_image</h2>
</div>
</div>
<div class="row">
<div class="col-sm-4">
{{ srcset_image(page.promo_image, "fill-{100x150,200x300}", sizes="30vw", alt="") }}
<p>Works</p>
{{ srcset_image(page.promo_image, "fill-{100x150,200x300}") }}
<p>Works (but no sizes so a bit pointless)</p>
</div>
<div class="col-sm-4">
{% set img=srcset_image(page.promo_image, "fill-{100x150,200x300}", sizes="30vw", alt="") %}
{{ img }}
<p>Assignment, direct rendering</p>
{% set bg=srcset_image(page.promo_image, "fill-{100x150,200x300}") %}
{% set fallback=bg.renditions[0] %}
<img srcset="{% for r in bg.renditions %}{{ r.url }} {{ r.width }}w{{ ', ' if not loop.last }}{% endfor %}" sizes="30vw" src="{{ fallback.url }}" width="{{ fallback.width }}" height="{{ fallback.height }} alt="">
<p>Assignment, data access</p>
</div>
<div class="col-sm-4">
{{ srcset_image(page.promo_image_missing, "fill-{100x150,200x300}", sizes="30vw", alt="") }}
<p>Missing image</p>
{# {{ srcset_image(page.promo_image, "fill-{100x150,200x300} jpegquality-40", sizes="30vw", alt="") }} #}
<p>Invalid spec, detected by regex (uncomment)</p>
{# {{ srcset_image(page.promo_image, "fill-}100x150,200x300}|jpegquality-40", sizes="30vw", alt="") }} #}
<p>Invalid spec, caught later</p>
{{ srcset_image(page.promo_image, "fill-{1x1,2x2,4x4,8x8,16x16,32x32,64x64,128x128,256x256,512x512}", sizes="5vw", alt="") }}
<p>10 images (just because you can…)</p>
{{ srcset_image(page.promo_image, "fill-100x150") }}
<p>Works the same as vanilla image</p>
</div>
</div>
</div>

<div class="container-fluid">
<div class="row">
<div class="col-sm-12">
<h2>picture, same as src_set</h2>
</div>
</div>
<div class="row">
<div class="col-sm-4">
{{ picture(page.promo_image, "fill-{100x150,200x300}", sizes="30vw", alt="") }}
<p>Works</p>
{{ picture(page.promo_image, "fill-{100x150,200x300}") }}
<p>Works (but no sizes so a bit pointless)</p>
</div>
<div class="col-sm-4">
{% set img=picture(page.promo_image, "fill-{100x150,200x300}", sizes="30vw", alt="") %}
{{ img }}
<p>Assignment, direct rendering</p>
{% set bg=picture(page.promo_image, "fill-{100x150,200x300}") %}
{% set fallback=bg.renditions[0] %}
<img srcset="{% for r in bg.renditions %}{{ r.url }} {{ r.width }}w{{ ', ' if not loop.last }}{% endfor %}" sizes="30vw" src="{{ fallback.url }}" width="{{ fallback.width }}" height="{{ fallback.height }} alt="">
<p>Assignment, data access</p>
</div>
<div class="col-sm-4">
{{ picture(page.promo_image_missing, "fill-{100x150,200x300}", sizes="30vw", alt="") }}
<p>Missing image</p>
{# {{ picture(page.promo_image, "fill-{100x150,200x300} jpegquality-40", sizes="30vw", alt="") }} #}
<p>Invalid spec, detected by regex (uncomment)</p>
{# {{ picture(page.promo_image, "fill-}100x150,200x300}|jpegquality-40", sizes="30vw", alt="") }} #}
<p>Invalid spec, caught later</p>
{{ picture(page.promo_image, "fill-{1x1,2x2,4x4,8x8,16x16,32x32,64x64,128x128,256x256,512x512}", sizes="5vw", alt="") }}
<p>10 sizes (just because you can…)</p>
{{ picture(page.promo_image, "fill-100x150") }}
<p>Works the same as vanilla image, but with a picture tag around it</p>
</div>
</div>
</div>

<div class="container-fluid">
<div class="row">
<div class="col-sm-12">
<h2>picture, formats</h2>
</div>
</div>
<div class="row">
<div class="col-sm-4">
{{ picture(page.promo_image, "format-{avif,jpeg}", alt="") }}
<p>Works</p>
</div>
<div class="col-sm-4">
{% set img=picture(page.promo_image, "format-{avif,jpeg}", alt="") %}
{{ img }}
<p>Assignment, direct rendering</p>
{% set bg=picture(page.promo_image, "format-{avif,jpeg}") %}
{% set fallback=bg.formats['jpeg'][0] %}
<picture>
<source srcset="{{ bg.formats['avif'][0].url }}" type="image/avif">
<img src="{{ fallback.url }}" alt="">
</picture>
<p>Assignment, data access</p>
</div>
<div class="col-sm-4">
{{ picture(page.promo_image, "format-{jpeg,avif,webp,gif,png}", alt="") }}
<p>All formats (just because you can…)</p>
</div>
</div>
</div>

<div class="container-fluid">
<div class="row">
<div class="col-sm-12">
<h2>picture, formats and sizes</h2>
</div>
</div>
<div class="row">
<div class="col-sm-4">
{{ picture(page.promo_image, "format-{avif,jpeg}|fill-{100x150,200x300}", sizes="30vw", alt="") }}
<p>Works</p>
</div>
<div class="col-sm-4">
{% set img=picture(page.promo_image, "format-{avif,jpeg}|fill-{100x150,200x300}", sizes="30vw", alt="") %}
{{ img }}
<p>Assignment, direct rendering</p>
{% set bg=picture(page.promo_image, "format-{avif,jpeg}|fill-{100x150,200x300}") %}
{% set avifs=bg.formats['avif'] %}
{% set fallbacks=bg.formats['jpeg'] %}
{% for r in avifs %}{{r.url}},{% endfor %}
{% for r in fallbacks %}{{r.url}},{% endfor %}
<p>Assignment, data access</p>
</div>
<div class="col-sm-4">
{{ picture(page.promo_image, "format-{jpeg,avif,webp,gif,png}|fill-{1x1,2x2,4x4,8x8,16x16,32x32,64x64,128x128,256x256,512x512}", alt="") }}
<p>All formats, 10 sizes (just because you can…)</p>
</div>
</div>
</div>

{% if page.body %}
<div class="container-fluid streamfield">
<div class="row">
Expand Down