I am having trouble getting images by name. craft.assets.first() function in assets gives the proper output of one image.

But when I try craft.assets.filename('flag.jpg'), craft shows the following error:

Object of class Craft\ElementCriteriaModel could not be converted to string

Same with other functions of assets. Please help me solve this error.

Thank You.


Please read the docs about ElementCriteriaModel craft.assets returns you an element of type ElementCriteriaModel so you can define criteria for your search. In order to fetch the elements you have to do first(), find(), last() or certain other functions.


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.