1

I have a Super Table "previewImage" with a field "previewImageFile".

This does not work:

  <ul class="col-lg-12">
  {% for subsection in entry.descendants.descendantDist(1).all() %}
    <li class="mb-4">
      <header>
        <h2 class="mb-2">{{ subsection.shortTitle }}</h2>
      </header>
      {% set image = subsection.previewImage.previewImageFile.one() %}
      {% if subsection.previewImage.previewImageType.value == 'jpg' %}
      {% set transformedImages = craft.imager.transformImage(image,
        [
          { height: 250, jpegQuality: 90 }
        ],
          {
            format: 'jpg',
            allowUpscale: false,
            resizeFilter: 'lanczos',
            effects: { unsharpMask: [0, 0.55, 0.55, 0.008] },
            interlace: false,
            convertToRGB: true
          }
      ) %}

      {% else %}

      {% set transformedImages = craft.imager.transformImage(image,
        [
          { height: 250 }
        ],
          {
            format: 'png',
            allowUpscale: false,
            resizeFilter: 'lanczos',
            effects: { unsharpMask: [0, 0.55, 0.55, 0.008] },
            interlace: false,
            convertToRGB: true
          }
      ) %}
      {% endif %}

      {% for image in subsection.previewImageFile %}
      <a href="{{ subsection.getUrl() }}" title="{{ subsection.linkTitle }}">
        <picture>
          <source class="img-fluid" srcset="{{ craft.imager.srcset(transformedImages) }}" type="image/jpeg">
          <img src="{{ transformedImages.url }}"
               srcset="{{ craft.imager.srcset(transformedImages) }}"
               sizes="(min-width: 1366px) 160px, (min-width: 1536px) 160px, 160px"
               width="auto"
               height="250"
               class="img-fluid mr-3"
               alt="{{ block.previewImageAltText }}">
        </picture>
        {% endfor %}
      </a>
    </li>
    {% endfor %}
  </ul>

I get the a (link) without images.

I guess previewImageFile.one() is wrong. But setting it to all throws a error:

get_class() expects parameter 1 to be object, array given
1

Its hard to see without the full context of field setup, but as you state, I believe its {% set image = subsection.previewImage.previewImageFile.one() %} that's the issue.

I can see further down you're correctly looking through subsection.previewImage, which are Super Table blocks. Like so:

{% for block in subsection.previewImage %}
   {% set image = block.previewImageFile.one() %}

The issue is that you're trying to call previewImageFile on the Super Table block element query, which isn't going to work.

Maybe you're trying to just look at the first block available and get the image from that? If so, you could do:

{% set image = subsection.previewImage[0].previewImageFile.one() %}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.