Error using assets operations 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.

craft.assets.filename('flag.jpg').first()