<p>This is more of a suggestion than a real answer (assuming the <code>folderId</code> and filename are correct, what you've got should probably work), but anyway:</p>

<p>I'd strongly advise against hard coding an Asset into a template like this. By creating a <a href="https://craftcms.com/docs/globals" rel="nofollow">Global set</a> with an Assets field, you'll save yourself a lot of (potential) trouble, both short and long term.</p>

<p>Here's how your code could look using a Global set called <code>siteSettings</code>, with an Assets field called <code>noMorePostsImage</code>:</p>

<pre><code>{% set asset = siteSettings.noMorePostsImage.first() %}
{% set thumb = {
    mode: 'crop',
    width: 800,
    height: 600,
    quality: 75,
    position: 'center-center'
} %}
{% if asset %}
    &lt;img alt="No More Posts" class="img-responsive center-block" src="{{ asset.getUrl(thumb) }}" /&gt;
{% endif %}
</code></pre>

<p>So, the code is (a little bit) simpler than what you currently have, and (more importantly) the chance of something going wrong is much smaller. As a bonus, it'll be much simpler to change the image later on, should the need arise. You'll also avoid future issues if someone e.g. moves or renames the Asset from inside Craft.</p>

<p>If your content editor(s) shouldn't be able to change or remove the image, you can simply exclude the Global set from your content editors' user group permissions (assuming you're not running Craft Personal, of course).</p>

CC BY-SA 3.0
2016-10-24T15:46:53.073Z
That worked perfectly! Thanks for introducing Globals to me. I had not even looked at this feature of craft.
hvs
CC BY-SA 3.0
2016-10-24T16:07:39.683Z
Awesome, very happy it helped you out :)
Mats Mikkel Rummelhoff
CC BY-SA 3.0
2016-10-22T11:27:11.527Z
2016-10-22T11:27:11.527Z
Mats Mikkel Rummelhoff
<p>I am trying to call an image in my twig template whose identity is known. Here is my code that does not work</p>

<pre><code>{% set asset = craft.assets.kind('image').folderId('9').filename('fitness-strength-strong-male-1.jpg') %}

{% set thumb = {
    mode: 'crop',
    width: 800,
    height: 600,
    quality: 75,
    position: 'center-center'
} %}

 {% if asset %}
    &lt;img alt="No More Posts" class="img-responsive center-block" src="{{ asset.getUrl(thumb) }}" &gt;
 {% endif %}    
</code></pre>

<p>This is not working at all. My <code>folderId</code> is correct (got it from <code>craft_assetfolders</code> table) and filename is copied and pasted. Not sure what I am doing wrong.</p>

CC BY-SA 3.0
2016-10-21T21:44:25.017Z
What happen if you do: `{% set asset = craft.assets.filename('fitness-strength-strong-male-1.jpg') %}`?
Brad Bell
<templating>
How to make calls to render a fixed asset
# How to make calls to render a fixed asset

(Asked by: username_0 on 2016-10-21)

I am trying to call an image in my twig template whose identity is known. Here is my code that does not work
{% set asset = craft.assets.kind('image').folderId('9').filename('fitness-strength-strong-male-1.jpg') %}

{% set thumb = {
    mode: 'crop',
    width: 800,
    height: 600,
    quality: 75,
    position: 'center-center'
} %}

 {% if asset %}
    
 {% endif %}    

This is not working at all. My folderId is correct (got it from craft_assetfolders table) and filename is copied and pasted. Not sure what I am doing wrong.

**Tags:** templating
> **Comments:**
> **username_1**: What happen if you do: `{% set asset = craft.assets.filename('fitness-strength-strong-male-1.jpg') %}`?  

---

## 1 answers

### Answer by username_2 on 2016-10-22. Score: 2 | Accepted answer

This is more of a suggestion than a real answer (assuming the folderId and filename are correct, what you've got should probably work), but anyway:
I'd strongly advise against hard coding an Asset into a template like this. By creating a Global set with an Assets field, you'll save yourself a lot of (potential) trouble, both short and long term.
Here's how your code could look using a Global set called siteSettings, with an Assets field called noMorePostsImage:
{% set asset = siteSettings.noMorePostsImage.first() %}
{% set thumb = {
    mode: 'crop',
    width: 800,
    height: 600,
    quality: 75,
    position: 'center-center'
} %}
{% if asset %}
    
{% endif %}

So, the code is (a little bit) simpler than what you currently have, and (more importantly) the chance of something going wrong is much smaller. As a bonus, it'll be much simpler to change the image later on, should the need arise. You'll also avoid future issues if someone e.g. moves or renames the Asset from inside Craft.
If your content editor(s) shouldn't be able to change or remove the image, you can simply exclude the Global set from your content editors' user group permissions (assuming you're not running Craft Personal, of course).

> **Comments:**
> **username_0**: That worked perfectly! Thanks for introducing Globals to me. I had not even looked at this feature of craft.  
> **username_2**: Awesome, very happy it helped you out :)  

---

