<p>2nd Revision:</p>

<p>The category group field layout is for categories within that group. Categories groups do not have fields assigned to them, only to the categories within a group.</p>

<hr>

<p>1st Revision:</p>

<p>To get the fields of a category group, set the category like so:</p>

<pre><code>{% set group = craft.categories.group('suitability').one() %}
</code></pre>

<p>And use fields:</p>

<pre><code>{{ group.someFieldHandle }}
</code></pre>

<hr>

<p>Original Answer:</p>

<p>To retrieve the category:</p>

<pre><code>{% set slug = craft.app.request.segment(1) %}
{% set category = craft.categories.group('suitability').slug(slug).one() %}
</code></pre>

<p>Then use its fields or related:</p>

<pre><code>{{ category.title }}
{{ category.somePlainTextField }}
{% set entries = craft.entries.relatedTo(category).all() %}
</code></pre>

<p>It would be better to set the template for the category on the category group settings page.</p>

<p>Set the URI to /suitability/{{ slug }} and the template to /shop/category.twig
Then you can just use the category in the template without having to set it by getting slug and pulling the category from the group. Also, this allows you to point multiple category groups to the same template if their template will be similar.</p>

CC BY-SA 4.0
2018-12-18T18:53:07.427Z
Ah, see don't want the category. I want the category group and to be able to access the group's data like: {{ group.title }}, {{ group.description }}
Jay
CC BY-SA 4.0
2018-12-18T18:58:19.327Z
Check revised answer.
Chattervast
CC BY-SA 4.0
2018-12-18T19:01:05.270Z
I've tried that before unfortunately. And that's just getting the first category within that category group not the group itself.
Jay
CC BY-SA 4.0
2018-12-18T19:02:02.317Z
Ah so how are you setting fields on the group itself?
Chattervast
CC BY-SA 4.0
2018-12-18T19:03:21.690Z
I'm setting the fields for the group in the CMS within a selected category group's field layout tab. But I'm not sure how to get the context of the group and not of a category within the said group.
Jay
CC BY-SA 4.0
2018-12-18T19:05:46.097Z
The field layout for a category group sets the fields for the categories in that group and not for the group itself.
Chattervast
CC BY-SA 4.0
2018-12-18T19:10:08.993Z
Oh yeah, course it does. Not to worry. Maybe I'm trying to do something that I don't think you can do...
Jay
CC BY-SA 4.0
2018-12-18T19:10:50.517Z
Sounds like it. I will update my answer to state that fields arent on groups but on the categories within a group.
Chattervast
CC BY-SA 4.0
2018-12-18T18:49:02.390Z
2018-12-18T19:11:59.473Z
2018-12-18T19:11:59.473Z
Chattervast
<p>I have a selection of category groups as follows:</p>

<pre><code>Suitability
Colour
Finish
etc
</code></pre>

<p>They all have many categories within them. I have set up some routes for <code>/suitability</code> etc to show the user a <code>/shop/category.twig</code> template for the category group landing pages.</p>

<p>But my issue I'm having is getting the context of the page based on the slug.</p>

<p>I have read a <a href="https://craftcms.stackexchange.com/questions/12253/display-category-group-name-in-template">very old SE post</a> that kind of offers a solution, but it's only useful for getting the name. I need to build on this to get the group. But it doesn't look like there's a way to 'get' a category group.</p>

<p>I may be wrong and missed something but I've only found ways to obtain category group info based on context of a category itself as follows:</p>

<pre><code>{# get the category group slug #}
{% set slug = craft.app.request.segment(1) %}

{# get the first category within this group and output the groups' name #}
{% set catGroupName = craft.categories.group(slug).first.group %}
</code></pre>

<p>Any advice on a much neater way to obtain a category group would be handy. Thanks</p>

<craft3><categories><category>
Method for creating Category Group landing pages
# Method for creating Category Group landing pages

(Asked by: username_0 on 2018-12-18)

I have a selection of category groups as follows:
Suitability
Colour
Finish
etc

They all have many categories within them. I have set up some routes for /suitability etc to show the user a /shop/category.twig template for the category group landing pages.
But my issue I'm having is getting the context of the page based on the slug.
I have read a very old SE post that kind of offers a solution, but it's only useful for getting the name. I need to build on this to get the group. But it doesn't look like there's a way to 'get' a category group.
I may be wrong and missed something but I've only found ways to obtain category group info based on context of a category itself as follows:
{# get the category group slug #}
{% set slug = craft.app.request.segment(1) %}

{# get the first category within this group and output the groups' name #}
{% set catGroupName = craft.categories.group(slug).first.group %}

Any advice on a much neater way to obtain a category group would be handy. Thanks

**Tags:** craft3, categories, category

---

## 1 answers

### Answer by username_1 on 2018-12-18. Score: 4 | Accepted answer

2nd Revision:
The category group field layout is for categories within that group. Categories groups do not have fields assigned to them, only to the categories within a group.

1st Revision:
To get the fields of a category group, set the category like so:
{% set group = craft.categories.group('suitability').one() %}

And use fields:
{{ group.someFieldHandle }}


Original Answer:
To retrieve the category:
{% set slug = craft.app.request.segment(1) %}
{% set category = craft.categories.group('suitability').slug(slug).one() %}

Then use its fields or related:
{{ category.title }}
{{ category.somePlainTextField }}
{% set entries = craft.entries.relatedTo(category).all() %}

It would be better to set the template for the category on the category group settings page.
Set the URI to /suitability/{{ slug }} and the template to /shop/category.twig
Then you can just use the category in the template without having to set it by getting slug and pulling the category from the group. Also, this allows you to point multiple category groups to the same template if their template will be similar.

> **Comments:**
> **username_0**: Ah, see don't want the category. I want the category group and to be able to access the group's data like: {{ group.title }}, {{ group.description }}  
> **username_1**: Check revised answer.  
> **username_0**: I've tried that before unfortunately. And that's just getting the first category within that category group not the group itself.  
> **username_1**: Ah so how are you setting fields on the group itself?  
> **username_0**: I'm setting the fields for the group in the CMS within a selected category group's field layout tab. But I'm not sure how to get the context of the group and not of a category within the said group.  
> **username_1**: The field layout for a category group sets the fields for the categories in that group and not for the group itself.  
> **username_0**: Oh yeah, course it does. Not to worry. Maybe I'm trying to do something that I don't think you can do...  
> **username_1**: Sounds like it. I will update my answer to state that fields arent on groups but on the categories within a group.  

---

