<div class="row catalogues">
<script>
function bytesToMB (bytes,decimals) { const megabytes = bytes / 1048576; return Math. round (megabytes * Math. pow (10, decimals)) / Math. pow (10, decimals); }
const getSize = async (id,link) => {
const client=new XMLHttpRequest();
client.open("HEAD",link,true);
client.send();
client.onreadystatechange = () => {
if (client.readyState === client.HEADERS_RECEIVED) {
const contentLength = client.getResponseHeader('Content-Length');
const contentLengthMb=bytesToMB(contentLength, 1);
document.getElementById(`_download_size_${id}`).innerHTML = contentLengthMb;
}
};
}
</script>
{% set blockCount = pimcore_block('myBlock').count %}
{% for i in pimcore_block('myBlock').iterator %}
{% if blockCount > 0 %}
{% set colClass = 'col-lg-' ~ (12 / blockCount) %}
{% else %}
{% set colClass = 'col-lg-6' %}
{% endif %}
{% if editmode %}
{{ pimcore_input('link_text') }}
{% endif %}
{% set link = pimcore_input('link_text') %}
<a href="{{ link ?: '#' }}" target="_blank" class="col-6 {{ colClass }} col-xl text-center d-flex flex-column align-items-center mb-40 catalogue">
{% if editmode %}
<div class="w-75">
{{ pimcore_image("image") }}
</div>
{% else %}
{#<img src="{{ pimcore_image("image").getSrc() }}" alt="{{ pimcore_image("image").getAlt() }}" class="w-75"/>#}
{{ pimcore_image("image").thumbnail('catalogues_thumbs').html({
'pictureAttributes': {
'class': ''
},
'imgAttributes': {
'class': 'w-75 h-auto'
}
}) | raw }}
{% endif %}
<span class="fs-20 fw-bold mb-10">
{{ pimcore_input("title",{
"width": '100%',
"placeholder": "Titolo"
}) }}
</span>
<span class="fs-16"><i class="fa fa-download me-10"></i>
Download (<span id="_download_size_{{ i }}"></span> Mb)
</span>
</a>
<script>
getSize('{{ i }}','{{ link }}');
</script>
{% endfor %}
</div>