<p>In Craft assets do not get "their own page" by default, but you can easily create them with a <a href="http://buildwithcraft.com/docs/routing#dynamic-routes">Dynamic Route</a>. So go to Settings → Routes and add a new route with a number token, e.g. <code>assets/&lt;number&gt;</code> and route those URIs to a new template, e.g. <code>assets/_entry</code>.</p>

<p>With this route set up you can now link to an asset's entry page like so:</p>

<pre><code>&lt;a href="{{ url('assets/' ~ asset.id) }}"&gt;
    &lt;img src="{{ asset.url('thumb') }}"&gt;
&lt;/a&gt;
</code></pre>

<p>In your assets/_entry.html template you do now <a href="http://buildwithcraft.com/docs/templating/craft.assets">query for your asset</a> via its ID, which is now available as a variable named "number". Use the <a href="http://buildwithcraft.com/docs/templating/exit"><code>exit</code></a> tag to 404 the request in case no asset was found for the given ID.</p>

<pre><code>{% set asset = craft.assets.id(number).first() %}

{% if not asset %}
    {% exit 404 %}
{% endif %}

&lt;figure&gt;
    &lt;img src="{{ asset.url('fullscreen') }}"&gt;
    &lt;figcaption&gt;{{ asset.caption }}&lt;/figcaption&gt;
&lt;/figure&gt;
</code></pre>

CC BY-SA 3.0
2015-08-23T14:41:38.413Z
2015-08-23T14:49:36.917Z
2015-08-23T14:49:36.917Z
carlcs
<p>It's not clear what exactly you mean by 'its own page'</p>

<p>Do you want to have an entry for each image? or a twig template that displays that image?</p>

<p>When you access a page by default <code>{{ entry.url }}</code> refers to the entry of the page you are currently on.</p>

<p>You can link to the <code>{{ asset.url }}</code> but I'm not certain that is what you are trying to achieve.</p>

<p>Please update your question so we can help you further.</p>

CC BY-SA 3.0
2015-08-23T02:24:19.710Z
2015-08-23T13:44:00.627Z
2015-08-23T13:44:00.627Z
j00lz
<p>I'm new to Craft CMS and can't figure out how to link images with the code below to its own page. Any suggestions?</p>

<pre><code>{% for asset in entry.mainImages %}

    &lt;a href="{# link to the image's page #}"&gt;
        &lt;img src="{{ asset.url('thumb') }}"&gt;
    &lt;/a&gt;

{% endfor %}
</code></pre>

<templating><assets><routes>
How do I link an image to its own page?
# How do I link an image to its own page?

(Asked by: username_0 on 2015-08-22)

I'm new to Craft CMS and can't figure out how to link images with the code below to its own page. Any suggestions?
{% for asset in entry.mainImages %}

    
        
    

{% endfor %}

**Tags:** templating, assets, routes


---

## 2 answers

### Answer by username_1 on 2015-08-23. Score: 5

In Craft assets do not get "their own page" by default, but you can easily create them with a Dynamic Route. So go to Settings → Routes and add a new route with a number token, e.g. assets/ and route those URIs to a new template, e.g. assets/_entry.
With this route set up you can now link to an asset's entry page like so:

    


In your assets/_entry.html template you do now query for your asset via its ID, which is now available as a variable named "number". Use the exit tag to 404 the request in case no asset was found for the given ID.
{% set asset = craft.assets.id(number).first() %}

{% if not asset %}
    {% exit 404 %}
{% endif %}


    
    {{ asset.caption }}


---

### Answer by username_2 on 2015-08-23. Score: 3

It's not clear what exactly you mean by 'its own page'

Do you want to have an entry for each image? or a twig template that displays that image?

When you access a page by default `{{ entry.url }}` refers to the entry of the page you are currently on.

You can link to the `{{ asset.url }}` but I'm not certain that is what you are trying to achieve.

Please update your question so we can help you further.


---

