<p>You can do this by creating a "single image" template, and point to that template with a URL GET variable containing the Asset ID, for example:</p>

<p><code>http://yoursite.com/gallery/single?assetId=234</code></p>

<p>First, create a template for your "single" image – e.g <code>/templates/gallery/single.twig</code> (I like to use the twig extension rather than .html, but its not important).</p>

<p>Add the following Twig code to your template – it will look at the current request query string for the <code>assetId</code> variable, and try to pull the relevant Asset:</p>

<pre><code>{% set assetId = craft.request.getParam( 'assetId' ) %}
{% if assetId %}
{% set asset = craft.assets.id( assetId ).first() %}
{% endif %}
</code></pre>

<p>Then, you can easily output the image in whatever way you want, here's an example:</p>

<pre><code>{% extends 'layouts/myGalleryTemplate' %}
{% block single %}
    {% if asset is defined %}
        &lt;img src="{{ asset.getUrl() }}" width="{{ asset.getWidth() }}" height="{{ asset.getHeight() }}" alt="" /&gt;
    {% else %}
        &lt;p class="error"&gt;The specified image could not be found&lt;/p&gt;
    {% endif %}
{% endblock %}
</code></pre>

CC BY-SA 3.0
2015-03-03T11:54:45.860Z
2015-03-03T12:08:57.040Z
2015-03-03T12:08:57.040Z
Mats Mikkel Rummelhoff
<p>As of right now I have nine or so structures created, each including it's own Image Gallery created in a Matrix.</p>

<p>Is it possible to give each image inside that matrix a unique URL?</p>

<p>What I'm trying to accomplish is to be able to create multiple galleries, each gallery when clicked will just pull up into a Fancybox. The problem with this, is there also needs to be social media sharing (Facebook, Twitter, Pinterest, and Google+) for each item in the gallery. After a bit of research the Facebook og:image tag only shares what is in that URL being shared. So I will need to be able to create pages for each item in the gallery. Would this be possible?</p>

<matrix><url><gallery>
Matrix Gallery, with every image having it's own unique URL?
# Matrix Gallery, with every image having it's own unique URL?

(Asked by: username_0 on 2015-01-14)

As of right now I have nine or so structures created, each including it's own Image Gallery created in a Matrix.

Is it possible to give each image inside that matrix a unique URL?

What I'm trying to accomplish is to be able to create multiple galleries, each gallery when clicked will just pull up into a Fancybox. The problem with this, is there also needs to be social media sharing (Facebook, Twitter, Pinterest, and Google+) for each item in the gallery. After a bit of research the Facebook og:image tag only shares what is in that URL being shared. So I will need to be able to create pages for each item in the gallery. Would this be possible?

**Tags:** matrix, url, gallery

---

## 1 answers

### Answer by username_1 on 2015-03-03. Score: 3 | Accepted answer

You can do this by creating a "single image" template, and point to that template with a URL GET variable containing the Asset ID, for example:
http://yoursite.com/gallery/single?assetId=234
First, create a template for your "single" image – e.g /templates/gallery/single.twig (I like to use the twig extension rather than .html, but its not important).
Add the following Twig code to your template – it will look at the current request query string for the assetId variable, and try to pull the relevant Asset:
{% set assetId = craft.request.getParam( 'assetId' ) %}
{% if assetId %}
{% set asset = craft.assets.id( assetId ).first() %}
{% endif %}

Then, you can easily output the image in whatever way you want, here's an example:
{% extends 'layouts/myGalleryTemplate' %}
{% block single %}
    {% if asset is defined %}
        
    {% else %}
        The specified image could not be found
    {% endif %}
{% endblock %}


---

