0

I have a bunch of categories within a section on my website, but I want each category item within that section to be able to have an additional slug. For example:

mywebsite.com/categories/category/information (information being the additional slug)

Is this possible with Craft?

  • What do you mean by "external link"? If you have a category group (and not just made a section and put your categories as entries) you can enable "Categories in this group have their own URLs" in your category group settings. craftcms.com/docs/categories – Tom De Smet Jun 2 '17 at 8:36
2

Update

Following your comment, and if I understand well, you already are using a URL for the categories, but want to create kind of a subpage "information" for them. It is a bit more complicated but it can be achieved. What you can do is create a route, either from the control panel or the config/routes.php file in craft/config. It may be easier to do it from the control panel first. If you go to Settings > Routes and click on "New route" you can enter the following information:

New route popup

It will create a new URI endpoint for the "information" pages that you want and map them to a _information.html template in the "categories" folder.

You can then create _information.html template and retrieve your category using the following code:

{% set category = craft.categories({ group: 'categoryName', slug: craft.request.segments[1] }) %}

Assuming the handle of your category is categoryName of course. craft.request.segments is an array containing all parts of your URI, starting from 0. Thus, the second part of the URI, which is the selected category's slug, is stored in craft.request.segments[1]. The variable category will then contain all the fields assigned to the category that you want to display in the information page.


It is possible and quite easy to do in Craft. You can create a new text field named "External link" for example, and assign it to the category.

To do that, go to Settings > Categories > {Name of your category} and select the "Field layout" tab. You can then assign the "External link" field to the category like you would for a section.

You can now edit your categories and add the external link for each one of them.

| improve this answer | |
  • What I meant by the external link was to have an additional slug onto of my category item, so it would add an additional page. So 'information' being that additional page which I could add fields to. Can this still be done with categories? – Amy Jun 2 '17 at 14:18
  • This is exactly what I was looking for, thank you! – Amy Jun 5 '17 at 9:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.