<p>I finally managed to answer my own question. I changed my routing to</p>

<p>/projects/slug/slug/gallery to projects/gallery/_entry</p>

<p>So was able to use a proper absolute link with /gallery added to the end</p>

<p>.com/projects/category/project/gallery</p>

<p>In the gallery _entry I used the following code to get the entry</p>

<p>{% set projectSlug = craft.request.getSegment(-2) %}
{% set categorySlug = craft.request.getSegment(-3) %} 
{% set category = craft.categories.slug(categorySlug).first() %}<br>
{% set entry = craft.entries.section('projects').slug(projectSlug).relatedTo(category).first() %}</p>

<p>This then worked fine, even if the same named project was used in two different categories</p>

<p>I would still prefer to do this without routing if anyone has any suggestions please? </p>

CC BY-SA 4.0
2018-08-01T09:03:41.660Z
2018-08-01T09:03:41.660Z
Jerry
<p>I have a site with projects which each has a projects structure with an associated category and a number of images.</p>

<p>The URL is set as <code>projects/{projectCat.first.slug}/{slug}</code></p>

<p>I want to use the structure first for a set of thumbnails for each project (easy - no problem) and then for a gallery page with full size images. Both pages will have the same set of images.
The URL for the first is <code>.com/projects/category/project-name</code>.</p>

<p>The only way I have been able to do it is to make the links from the thumbnail page using:</p>

<pre><code>&lt;a href="/projects/gallery/{{ category.slug }}/{{ entry.slug }}"&gt;
</code></pre>

<p>and then using routing:</p>

<pre><code>/projects/gallery/slug/slug to projects/gallery/_entry
</code></pre>

<p>This works but if I have a project in two or more categories with the same name it doesn't take account of the category in the URL and is also a bit messy.</p>

<p>Is there a better way?</p>

CC BY-SA 4.0
2018-07-26T12:56:56.107Z
I'm having trouble understanding your issue – can you rephrase/be more specific? What exactly goes wrong if a project entry has "two or more categories with the same name"? Also, since you're using the category _slug_ in the URLs, I don't really understand how multiple categories with the same _name_ would even be an issue – the `slug` will always be unique (within the same Category Group), even if the _name_ is identical, no? And since it's only possible to set a Categories Field to a single Category Group, identical _names_ shouldn't be an issue.
Mats Mikkel Rummelhoff
CC BY-SA 4.0
2018-07-26T16:44:34.900Z
Thanks @Mats - the problem is that my link is just a relative path with the category name followed by the project name, and the two are not related so Craft just uses the project name in isolation so the relation of the project to the category is not there. The actual ling from the structure URL woks fine, but not the hand done one Link i
Jerry
CC BY-SA 4.0
2018-07-26T16:56:01.607Z
Thanks @Mats - the problem is that my link is just a relative path with the category name followed by the project name, and the two are not related so Craft just uses the project name in isolation so the relation of the project to the category is not there. The actual link from the structure URL woks fine, but not the hand coded one. I only have one entry type for the structure so don't seem to be able to use that. Site is [link](http://dev.andersonorr.com/projects/traditional-homes)
Jerry
<templating><structure><category>
Craft 2 use different template for the same structure
# Craft 2 use different template for the same structure

(Asked by: username_0 on 2018-07-25)

I have a site with projects which each has a projects structure with an associated category and a number of images.
The URL is set as projects/{projectCat.first.slug}/{slug}
I want to use the structure first for a set of thumbnails for each project (easy - no problem) and then for a gallery page with full size images. Both pages will have the same set of images.
The URL for the first is .com/projects/category/project-name.
The only way I have been able to do it is to make the links from the thumbnail page using:


and then using routing:
/projects/gallery/slug/slug to projects/gallery/_entry

This works but if I have a project in two or more categories with the same name it doesn't take account of the category in the URL and is also a bit messy.
Is there a better way?

**Tags:** templating, structure, category
> **Comments:**
> **username_1**: I'm having trouble understanding your issue – can you rephrase/be more specific? What exactly goes wrong if a project entry has "two or more categories with the same name"? Also, since you're using the category _slug_ in the URLs, I don't really understand how multiple categories with the same _name_ would even be an issue – the `slug` will always be unique (within the same Category Group), even if the _name_ is identical, no? And since it's only possible to set a Categories Field to a single Category Group, identical _names_ shouldn't be an issue.  
> **username_0**: Thanks @Mats - the problem is that my link is just a relative path with the category name followed by the project name, and the two are not related so Craft just uses the project name in isolation so the relation of the project to the category is not there. The actual ling from the structure URL woks fine, but not the hand done one Link i  
> **username_0**: Thanks @Mats - the problem is that my link is just a relative path with the category name followed by the project name, and the two are not related so Craft just uses the project name in isolation so the relation of the project to the category is not there. The actual link from the structure URL woks fine, but not the hand coded one. I only have one entry type for the structure so don't seem to be able to use that. Site is [link](http://dev.andersonorr.com/projects/traditional-homes)  

---

## 1 answers

### Answer by username_0 on 2018-08-01. Score: 1

I finally managed to answer my own question. I changed my routing to

/projects/slug/slug/gallery to projects/gallery/\_entry

So was able to use a proper absolute link with /gallery added to the end

.com/projects/category/project/gallery

In the gallery \_entry I used the following code to get the entry

{% set projectSlug = craft.request.getSegment(-2) %}
{% set categorySlug = craft.request.getSegment(-3) %}
{% set category = craft.categories.slug(categorySlug).first() %}  
{% set entry = craft.entries.section('projects').slug(projectSlug).relatedTo(category).first() %}

This then worked fine, even if the same named project was used in two different categories

I would still prefer to do this without routing if anyone has any suggestions please?


---

