Skip to content

Commit

Permalink
Use img tag in hero picture template
Browse files Browse the repository at this point in the history
This allows using source filetypes
  • Loading branch information
stefanw committed Oct 30, 2023
1 parent f86634a commit c2c2a14
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 32 deletions.
45 changes: 17 additions & 28 deletions fragdenstaat_de/templates/djangocms_picture/hero/picture.html
Original file line number Diff line number Diff line change
@@ -1,33 +1,22 @@
{% load cms_tags %}
{% load thumbnail %}
{% load fds_cms_tags %}

<style>
#hero-image-{{ instance.pk }} {
background-image: url('{% thumbnail instance.picture 450x450 crop subject_location=instance.picture.subject_location %}');
}
@media(min-width:576px){
#hero-image-{{ instance.pk }} {
background-image: url('{% thumbnail instance.picture 768x400 crop subject_location=instance.picture.subject_location %}');
}
}
@media(min-width:768px){
#hero-image-{{ instance.pk }} {
background-image: url('{% thumbnail instance.picture 992x400 crop subject_location=instance.picture.subject_location %}');
}
}
@media(min-width:992px){
#hero-image-{{ instance.pk }} {
background-image: url('{% thumbnail instance.picture 1200x400 crop subject_location=instance.picture.subject_location %}');
}
}
@media(min-width:1200px){
#hero-image-{{ instance.pk }} {
background-image: url('{% thumbnail instance.picture 1920x400 crop subject_location=instance.picture.subject_location %}');
}
}
</style>
<div class="hero-image{% if instance.attributes.class %} {{ instance.attributes.class }}{% endif %}" id="hero-image-{{ instance.pk }}" {{ instance.attributes_str }}>
<div class="hero-image{% if instance.attributes.class %} {{ instance.attributes.class }}{% endif %}" {{ instance.attributes_str }}>
{% with picture=instance.picture %}
{% get_responsive_filer_image picture "col-12" as respimg %}
<picture>
{% for source in respimg.sources %}
<source
srcset="{{ source.srcset }}"
sizes="{{ respimg.sizes }}"
type="{{ source.mime_type }}"
/>
{% endfor %}

<img class="hero-image-img" loading="lazy" width="{{ picture.width|floatformat:"0u" }}" height="{{ picture.height|floatformat:"0u" }}" src="{{ respimg.src }}" srcset="{{ respimg.srcset }}" sizes="{{ respimg.sizes }}" alt="">
</picture>
{% endwith %}
{% for plugin in instance.child_plugin_instances %}
{% render_plugin plugin %}
{% endfor %}
</div>
</div>
16 changes: 12 additions & 4 deletions frontend/styles/cms_elements.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,20 @@
}

.hero-image {
margin: 0;
background-position: center 0;
background-repeat: no-repeat;
background-size: cover;
display: flex;
overflow: hidden;
position: relative;
width: 100%;
min-height: 24rem;
}
.hero-image-img {
pointer-events: none;
position: absolute;
width: 100%;
height: 100%;
z-index: -1;
object-fit: cover;
}

/* Submenu */

Expand Down

0 comments on commit c2c2a14

Please sign in to comment.