1

Is it possible to set an inline image transform's settings from the output of a Matrix block field?

For example

{% set transform = {
  mode: 'block.imageMode',
  width: block.imageWidth,
  position: 'block.imageFocus'
} %}

Each time I've tried this, the image gives 404. I know the surrounding code works as expected because hard coding the values, the image displays as we'd expect.

This works just fine:

{% set transform = {
  mode: 'crop',
  width: 300,
  quality: 70,
  position: 'center-center'
} %}

EDIT:

Some surrounding code for context

{% for image in block.image %}

{% set transform = {
  mode: block.imageMode,
  width: block.imageWidth,
  quality: 70,
  position: block.focalPoint
} %}

<div class="figure  image--{{ block.imagePosition }}">
  <p>
    <img src="{{ image.getUrl(transform) }}" width="{{ image.getWidth(transform) }}" height="{{ image.getHeight(transform) }}" alt="{{ image.title }}">
    {% if image.title %}<b class="figure__caption">{{ image.title }}</b>{% endif %}
  </p>
</div>
<!-- // .figure -->

{% endfor %}
2

Try it without the quotes:

{% set transform = {
       mode: block.imageMode,
       width: block.imageWidth,
       position: block.imageFocus
   }
%}
| improve this answer | |
  • negative - even tried putting the quotes into the actual dropdown selector value in the CP. The src of the image is <img src="craft.dev/resources/transforms/9?x=JnxyQdEtY" width="300" height="105" alt="WebBanner"> – Steven Grant Jan 24 '15 at 18:34
  • would it make a difference that the image is also coming from S3? – Steven Grant Jan 24 '15 at 19:34
  • Do a dump(transform) and see what that outputs. – Brad Bell Jan 24 '15 at 20:07
  • d.pr/n/19IcA – Steven Grant Jan 24 '15 at 22:17
  • 2
    lol - let's just say I fixed it and call it a day. :) – Brad Bell Jan 25 '15 at 2:05

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.