With the ImageOptimize plugin for Craft 3, you create an OptimizedImages field type and then assign that to the Field Layout of your chosen Asset Volume. As far as I can tell (I'm very new to Craft), this means that it won't work to add an Assets field inside a Matrix because it doesn't have the OptimizedImages field associated with it. (I've tried, and received Calling unknown method: craft\elements\Asset::optimizedImages())

Is anyone aware of a possible workaround? I'm guessing that something like Craft Neo, which allows you use existing fields in a Matrix, would be a solution, but at this early stage, there is no version of the plugin for Craft 3.

Thanks for any insight!

1 Answer 1


I'm also using ImageOptimize and yes, it does work within Matrix. Your image has to have the call to the plugin code as specified in the plugin docs. Additionally, your image calls must match the image size you've setup within the plugin preferences panel. Within Matrix, you are calling the assets Field Type.

Here's a sample:

{% if block.type == "graphicCalloutBlock" %}
        {# Full Width Image #}  
        {% set image = block.graphicCalloutImage.one() %}
            <div class="block">                               
                 {% if image | length %}
                 <img alt=""
                 src="{{ image.optimizedImages.src() }}"
                 srcset="{{ image.optimizedImages.srcset() }}"
                 sizes="(min-width: 480px) 100vw, (min-width: 880px) 75vw, (min-width: 1024px) 50vw,  800px" 
                {% endif %}
            </div><!-- end block -->
{% endif %}
  • Well, shoot... I had a typo. I was calling {{ image.optimizedImages().src() }} instead of {{ image.optimizedImages.src() }}. Thank you for your answer! Dec 11, 2017 at 16:14

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.