1

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.

1 Answer 1

2

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.

craft.assets.filename('flag.jpg').first()
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.