Answers.Body: <p>Please read the docs about <a href="https://craftcms.com/docs/templating/elementcriteriamodel" rel="nofollow noreferrer">ElementCriteriaModel</a> <code>craft.assets</code> returns you an element of type <code>ElementCriteriaModel</code> so you can define criteria for your search. In order to fetch the elements you have to do <code>first()</code>, <code>find()</code>, <code>last()</code> or certain other functions.</p>
  
  <pre><code>craft.assets.filename('flag.jpg').first()
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-04-01T08:53:40.920Z
Answers.LastActivityDate: 2018-04-01T08:53:40.920Z
Answers.UserDisplayName: Robin Schambach
Body: <p>I am having trouble getting images by name. <code>craft.assets.first()</code> function in assets gives the proper output of one image.</p>
  
  <p>But when I try <code>craft.assets.filename('flag.jpg')</code>, craft shows the following error:</p>
  
  <blockquote>
    <p>Object of class Craft\ElementCriteriaModel could not be converted to string</p>
  </blockquote>
  
  <p>Same with other functions of assets. Please help me solve this error.</p>
  
  <p>Thank You.</p>
  
Tags: <templating><assets><elementcriteriamodel>
Title: Error using assets operations
ThreadText: # Error using assets operations
  
  (Asked by: username_0 on 2018-04-01)
  
  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.
  
  **Tags:** templating, assets, elementcriteriamodel
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-04-01. Score: 2 | Accepted answer
  
  Please read the docs about [ElementCriteriaModel](https://craftcms.com/docs/templating/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()
  
  ```
  
  
  ---
  
  