Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinDev committed Dec 12, 2022
1 parent 5ced135 commit bd62159
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 51 deletions.
25 changes: 13 additions & 12 deletions packages/core/src/templates/component/image_helper.html.twig
@@ -1,14 +1,15 @@

{% macro thumb(image, page = null, default_filter = 'thumb', otherAttributes = {}) %}{% apply spaceless %}
<picture>
<source type="image/webp" srcset="{{ image|image(default_filter, 'webp') }} 576w" />
<img srcset="{{ image|image(default_filter) }} 576w"
src="{{ image|image('default') }}"
loading="lazy"
width="{{ image.width }}" height="{{ image.height }}"
{% if otherAttributes.alt is not defined %}
alt="{{ image.nameByLocale(page is not null ? page.locale : '') }}"
{% endif %}
{{ otherAttributes ? attr(otherAttributes) : '' }} />
</picture>
{% macro thumb(image, page = null, filter = 'thumb', otherAttributes = {}) %}{% apply spaceless %}
<picture>
<source type="image/webp" srcset="{{ image|image(filter, 'webp') }} 576w" />
<img srcset="{{ image|image(filter) }} 576w"
src="{{ image|image('default') }}"
loading="lazy"
width="{{ filter == 'thumb' ? '1' : image.width }}"
height="{{ filter == 'thumb' ? '1' : image.height }}"
{% if otherAttributes.alt is not defined %}
alt="{{ image.nameByLocale(page is not null ? page.locale : '') }}"
{% endif %}
{{ otherAttributes ? attr(otherAttributes) : '' }} />
</picture>
{% endapply %}{% endmacro %}
78 changes: 39 additions & 39 deletions packages/core/src/templates/component/image_inline.html.twig
@@ -1,38 +1,38 @@
{#
string image_src ...
strubg image_alt image.name(page is defined ? page.locale : '')
bool image_link default: true
array image_attr
string image_wrapper default: 'p' if image_wrapper_class is setted
string image_wrapper_class default: 'w-full h-auto' if image_wrapper is setted
string image_src ...
strubg image_alt image.name(page is defined ? page.locale : '')
bool image_link default: true
array image_attr
string image_wrapper default: 'p' if image_wrapper_class is setted
string image_wrapper_class default: 'w-full h-auto' if image_wrapper is setted
xs: #576px
sm: #768px
md: #992px
lg: #1200px
xl: #1200px+
xs: #576px
sm: #768px
md: #992px
lg: #1200px
xl: #1200px+
#}

{% block inline_image %}
{% if image_src is defined %}
{% if image_wrapper_class is defined or image_wrapper is defined %}
<{{ image_wrapper|default('p') }} {% if image_wrapper_class is defined %}class="{{ image_wrapper_class }}"{% endif %}>
{% endif %}
{% if image_wrapper_class is defined or image_wrapper is defined %}
<{{ image_wrapper|default('p') }} {% if image_wrapper_class is defined %}class="{{ image_wrapper_class }}"{% endif %}>
{% endif %}

{% set image = media_from_string(image_src, image_alt ?? '') %}
{% set image_html = _self.renderImage(image, image_class ?? null,
image_attr ?? null, image_alt ?? null, lazy ?? true) %}
{% set image = media_from_string(image_src, image_alt ?? '') %}
{% set image_html = _self.renderImage(image, image_class ?? null,
image_attr ?? null, image_alt ?? null, lazy ?? true) %}

{% if image_link is not defined or image_link != false %}
{% if image_link is not defined or image_link != false %}

{{ link(image_html, image_link|default(image|image('default')), image_link is not defined ? {'data-fslightbox': 'inline', 'dwl': image|image('default', 'webp')} : {}) }}
{% else %}
{{ image_html }}
{% endif %}
{{ link(image_html, image_link|default(image|image('default')), image_link is not defined ? {'data-fslightbox': 'inline', 'dwl': image|image('default', 'webp')} : {}) }}
{% else %}
{{ image_html }}
{% endif %}

{% if image_wrapper_class is defined %}
</{{ image_wrapper|default('p') }}>
{% endif %}
{% if image_wrapper_class is defined %}
</{{ image_wrapper|default('p') }}>
{% endif %}
{% endif %}
{% endblock %}

Expand All @@ -48,21 +48,21 @@
{% endif %}
<picture>
<source type="image/webp"
srcset="{{ image|image('xs', 'webp') ~' 576w'
~','~ image|image('sm', 'webp') ~' 768w'
~','~ image|image('md', 'webp') ~' 992w'
~','~ image|image('lg', 'webp') ~' 1200w'
~','~ image|image('xl', 'webp') ~' 1600w' }}" />
srcset="{{ image|image('xs', 'webp') ~' 576w'
~','~ image|image('sm', 'webp') ~' 768w'
~','~ image|image('md', 'webp') ~' 992w'
~','~ image|image('lg', 'webp') ~' 1200w'
~','~ image|image('xl', 'webp') ~' 1600w' }}" />
<img {{ mergeAttr({srcset: image|image('xs') ~' 576w'
~','~ image|image('sm') ~' 768w'
~','~ image|image('md') ~' 992w'
~','~ image|image('lg') ~' 1200w'
~','~ image|image('xl') ~' 1600w',
src: image|image('default'),
class: image_class is defined and image_class ? image_class : 'w-full h-auto',
width: width,
height: height,
alt: image_alt|default(image.alt)
~','~ image|image('sm') ~' 768w'
~','~ image|image('md') ~' 992w'
~','~ image|image('lg') ~' 1200w'
~','~ image|image('xl') ~' 1600w',
src: image|image('default'),
class: image_class is defined and image_class ? image_class : 'w-full h-auto',
width: width,
height: height,
alt: image_alt|default(image.alt)
}, image_attr ?? {}, lazy ? {loading: 'lazy'} : {}) }} />
</picture>
{% endmacro %}

0 comments on commit bd62159

Please sign in to comment.