|
1 | | -{% apply spaceless %} |
2 | | - {% set attributes = { |
3 | | - 'alt' : alt|escape('html_attr'), |
4 | | - } %} |
| 1 | +{%- set attributes = { |
| 2 | + 'alt' : alt|escape('html_attr'), |
| 3 | +} -%} |
5 | 4 |
|
6 | | - {% if alt is empty %} |
7 | | - {% set attributes = attributes|merge({'aria-hidden' : 'true'}) %} |
8 | | - {% endif %} |
9 | | - {% if lazyload %} |
10 | | - {% set attributes = attributes|merge({'data-src' : url}) %} |
11 | | - {% set attributes = attributes|merge({'src' : fallback}) %} |
12 | | - {% if srcset %} |
13 | | - {% set attributes = attributes|merge({'data-srcset' : srcset}) %} |
14 | | - {% endif %} |
15 | | - {% if sizes %} |
16 | | - {% set attributes = attributes|merge({'sizes' : sizes}) %} |
17 | | - {% endif %} |
18 | | - {% if class %} |
19 | | - {% set originalClass = class %} |
20 | | - {% set class = class ~ ' ' ~ lazyload_class %} |
21 | | - {% else %} |
22 | | - {% set originalClass = '' %} |
23 | | - {% set class = lazyload_class %} |
24 | | - {% endif %} |
25 | | - {% else %} |
26 | | - {% set originalClass = class %} |
27 | | - {% set attributes = attributes|merge({'src' : url}) %} |
28 | | - {% if srcset %} |
29 | | - {% set attributes = attributes|merge({'srcset' : srcset}) %} |
30 | | - {% endif %} |
31 | | - {% if sizes %} |
32 | | - {% set attributes = attributes|merge({'sizes' : sizes}) %} |
33 | | - {% endif %} |
34 | | - {% endif %} |
| 5 | +{%- if alt is empty -%} |
| 6 | + {%- set attributes = attributes|merge({'aria-hidden' : 'true'}) -%} |
| 7 | +{%- endif -%} |
| 8 | +{%- if lazyload -%} |
| 9 | + {%- set attributes = attributes|merge({'data-src' : url}) -%} |
| 10 | + {%- set attributes = attributes|merge({'src' : fallback}) -%} |
| 11 | + {%- if srcset -%} |
| 12 | + {%- set attributes = attributes|merge({'data-srcset' : srcset}) -%} |
| 13 | + {%- endif -%} |
| 14 | + {%- if sizes -%} |
| 15 | + {%- set attributes = attributes|merge({'sizes' : sizes}) -%} |
| 16 | + {%- endif -%} |
| 17 | + {%- if class -%} |
| 18 | + {%- set originalClass = class -%} |
| 19 | + {%- set class = class ~ ' ' ~ lazyload_class -%} |
| 20 | + {%- else -%} |
| 21 | + {%- set originalClass = '' -%} |
| 22 | + {%- set class = lazyload_class -%} |
| 23 | + {%- endif -%} |
| 24 | +{%- else -%} |
| 25 | + {%- set originalClass = class -%} |
| 26 | + {%- set attributes = attributes|merge({'src' : url}) -%} |
| 27 | + {%- if srcset -%} |
| 28 | + {%- set attributes = attributes|merge({'srcset' : srcset}) -%} |
| 29 | + {%- endif -%} |
| 30 | + {%- if sizes -%} |
| 31 | + {%- set attributes = attributes|merge({'sizes' : sizes}) -%} |
| 32 | + {%- endif -%} |
| 33 | +{%- endif -%} |
35 | 34 |
|
36 | | - {% if loading %} |
37 | | - {% set attributes = attributes|merge({'loading' : loading|escape('html_attr')}) %} |
38 | | - {% endif %} |
39 | | - {% if averageColor %} |
40 | | - {% set attributes = attributes|merge({ |
41 | | - 'data-average-color': averageColor|escape('html_attr') |
42 | | - }) %} |
43 | | - {% endif %} |
44 | | - {% if ratio %} |
45 | | - {% set attributes = attributes|merge({ |
46 | | - 'data-ratio': ratio|escape('html_attr') |
47 | | - }) %} |
48 | | - {% endif %} |
49 | | - {% if width and not sizes %} |
50 | | - {% set attributes = attributes|merge({'width' : width|escape('html_attr')}) %} |
51 | | - {% endif %} |
52 | | - {% if height and not sizes %} |
53 | | - {% set attributes = attributes|merge({'height' : height|escape('html_attr')}) %} |
54 | | - {% endif %} |
55 | | - {% if width and ratio and not height and not sizes %} |
56 | | - {% set attributes = attributes|merge({'height' : (width / ratio)|round|escape('html_attr')}) %} |
57 | | - {% endif %} |
58 | | - {% if height and ratio and not width and not sizes %} |
59 | | - {% set attributes = attributes|merge({'width' : (height * ratio)|round|escape('html_attr')}) %} |
60 | | - {% endif %} |
61 | | - {% if class %} |
62 | | - {% set attributes = attributes|merge({'class' : class|escape('html_attr')}) %} |
63 | | - {% endif %} |
64 | | - {% if identifier %} |
65 | | - {% set attributes = attributes|merge({'id' : identifier|escape('html_attr')}) %} |
66 | | - {% endif %} |
| 35 | +{%- if loading -%} |
| 36 | + {%- set attributes = attributes|merge({'loading' : loading|escape('html_attr')}) -%} |
| 37 | +{%- endif -%} |
| 38 | +{%- if averageColor -%} |
| 39 | + {%- set attributes = attributes|merge({ |
| 40 | + 'data-average-color': averageColor|escape('html_attr') |
| 41 | + }) -%} |
| 42 | +{%- endif -%} |
| 43 | +{%- if ratio -%} |
| 44 | + {%- set attributes = attributes|merge({ |
| 45 | + 'data-ratio': ratio|escape('html_attr') |
| 46 | + }) -%} |
| 47 | +{%- endif -%} |
| 48 | +{%- if width and not sizes -%} |
| 49 | + {%- set attributes = attributes|merge({'width' : width|escape('html_attr')}) -%} |
| 50 | +{%- endif -%} |
| 51 | +{%- if height and not sizes -%} |
| 52 | + {%- set attributes = attributes|merge({'height' : height|escape('html_attr')}) -%} |
| 53 | +{%- endif -%} |
| 54 | +{%- if width and ratio and not height and not sizes -%} |
| 55 | + {%- set attributes = attributes|merge({'height' : (width / ratio)|round|escape('html_attr')}) -%} |
| 56 | +{%- endif -%} |
| 57 | +{%- if height and ratio and not width and not sizes -%} |
| 58 | + {%- set attributes = attributes|merge({'width' : (height * ratio)|round|escape('html_attr')}) -%} |
| 59 | +{%- endif -%} |
| 60 | +{%- if class -%} |
| 61 | + {%- set attributes = attributes|merge({'class' : class|escape('html_attr')}) -%} |
| 62 | +{%- endif -%} |
| 63 | +{%- if identifier -%} |
| 64 | + {%- set attributes = attributes|merge({'id' : identifier|escape('html_attr')}) -%} |
| 65 | +{%- endif -%} |
67 | 66 |
|
68 | | - {% set attributesCompiled = {} %} |
69 | | - {% for key, value in attributes %} |
70 | | - {% if value is same as(true) %} |
71 | | - {% set attributesCompiled = attributesCompiled|merge([key]) %} |
72 | | - {% else %} |
73 | | - {% set attributesCompiled = attributesCompiled|merge([key ~ '="' ~ value ~ '"']) %} |
74 | | - {% endif %} |
75 | | - {% endfor %} |
76 | | - |
77 | | - <img {{ attributesCompiled|join(' ')|raw }} /> |
78 | | - {% if lazyload and not avoidNoScript %} |
79 | | - {% block noscript %} |
80 | | - <noscript{% block noscript_attributes %}{% endblock %}> |
81 | | - {% include 'documents/image.html.twig' with { |
82 | | - 'lazyload': false, |
83 | | - 'class': originalClass, |
84 | | - 'avoidNoScript': true |
85 | | - } %} |
86 | | - </noscript> |
87 | | - {% endblock %} |
88 | | - {% endif %} |
89 | | -{% endapply %} |
| 67 | +{%- set attributesCompiled = {} -%} |
| 68 | +{%- for key, value in attributes -%} |
| 69 | + {%- if value is same as(true) -%} |
| 70 | + {%- set attributesCompiled = attributesCompiled|merge([key]) -%} |
| 71 | + {%- else -%} |
| 72 | + {%- set attributesCompiled = attributesCompiled|merge([key ~ '="' ~ value ~ '"']) -%} |
| 73 | + {%- endif -%} |
| 74 | +{%- endfor -%} |
| 75 | +<img {{ attributesCompiled|join(' ')|raw }} /> |
| 76 | +{%- if lazyload and not avoidNoScript -%} |
| 77 | + {%- block noscript -%} |
| 78 | + <noscript{% block noscript_attributes %}{%- endblock -%}> |
| 79 | + {%- include 'documents/image.html.twig' with { |
| 80 | + 'lazyload': false, |
| 81 | + 'class': originalClass, |
| 82 | + 'avoidNoScript': true |
| 83 | + } -%} |
| 84 | + </noscript> |
| 85 | + {%- endblock -%} |
| 86 | +{%- endif -%} |
0 commit comments