0

I would like to display images from various sections, in this case the home page. I am still coming to terms with Twig/Craft's criteria models and the transform makes it confusing.

{% for image in craft.entries.section('news').limit(1) %}
    {% set transformedImage = craft.imager.transformImage(image, { width: 1420, height: 550, position: image.focalPoint }) %}

    <img src="{{ image.bannerImage.first().getUrl }}" alt="" />
{% endfor %}` 

Where do you then define the image? (bannerImage is a asset field)

1
  • Can you please rewrite this question so it has context for other people who may be viewing.
    – Fyrebase
    Commented Jan 9, 2017 at 7:08

1 Answer 1

2

Try the following, it should do what you are after.

{#
  Generate array of entries comprised of first
  entry from each section
#}
{% set entries = [
  craft.entries.section('news').first(),
  craft.entries.section('other_section').first(),
  craft.entries.section('yet_another_section').first()
] %}

{# Loop through entry array #}
{% for entry in entries %}
  {% if entry.bannerSlider|length %}
    {% set image = entry.bannerSlider.first() %}
    {% set transformedImage = craft.imager.transformImage(image, { width: 1420, height: 550, position: image.focalPoint,  effects: { grayscale: true, gamma: 1.5}, }) %}
    <li data-transition="" data-masterspeed="500">
    <img src="{{ transformedImage.url }}"/>
  {% endif %}
{% endfor %}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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