I'm trying to mimic the URL structure exactly how I have it in my old CMS. If I select an entry to have both a category and subcategory I would like to have the subcategory in the URL along with the category and the entry slug.

For Example


Right now I have the Entry URL Format set to be {category.first().slug}/{slug}, but that only shows the first category. How do I access that optional subcat1 subcategory in that field?


I have tried the following but it doesn't work

{category.first.slug }/{ category.first.children.first.slug ? category.first.children.first.slug ~ '/' : '' }{slug}

I have also tried

{category[0].slug}/{ category[1] ? category[1].slug ~ '/': ''}{slug}
  • Can you try and use double curly braces {{ .. }} , if I remember correctly there was a change in Craft 2.0 which makes them necessary.
    – Victor
    Jun 20, 2014 at 18:46
  • Just tried that, no difference unfortunately. Jun 20, 2014 at 18:48
  • It seems that you want both of the following to load the entry template: example.com/cat1/subcat1/entry & example.com/cat1/entry Is this correct? Probably you will need to use custom routes, and a bit of template logic to determine if a request segment is a category url or an entry url. I've not run into a need for segment 1 as a category url, it has always been something like /catalog/cat/entry or news/cat/entry/ Is there a specific reason you are not doing this way? Jun 20, 2014 at 20:01
  • Because the CMS I used before – Wordpress – structures posts with subcategories in the URL in this way. To be honest it makes the most sense, otherwise what is the point of subcategories in the first place? Jun 20, 2014 at 20:03
  • So .com/cat1/ would list all entries in cat1 including its subs, and .com/cat1/sub1/ would list only sub1 entries? Then you have .com/cat1/entryA/ and .com/cat1/sub1/entryA/ ? Craft is so flexible, you can make it behave however you need. It will help if you update your question with more example urls and what you expect to happen with each one. :) Jun 20, 2014 at 20:11

1 Answer 1


If you go into your Category Group’s settings and set the following settings:

  • Craft 2
    • Top Level URL Format: {slug}
    • Nested URL Format: {parent.uri}/{slug}
  • Craft 3
    • Category URI Format: {parent.uri}/{slug}

then you would be able to set your section’s Entry URL Format to this:

  • Craft 2

  • Craft 3

  • This is handy. Is there an easy way to just output just the child category and not include the parent?
    – shorn
    Jul 10, 2014 at 9:33
  • @shorn Not sure I’m following. Maybe post as its own question with more details? Jul 10, 2014 at 13:14
  • Ok, will post up a question shortly.
    – shorn
    Jul 10, 2014 at 17:05
  • 1
    In regards to the Category URI Format, if you have a prefix before all category URI's, the example given here for Craft 3 results in the prefix being duplicated. In this case the following solution worked for me: prefix/{parent.slug}/{slug} (using parent.slug rather than parent.uri).
    – Mike
    Jun 18, 2019 at 16:11
  • @Mike - The problem with your solution prefix/{parent.slug}/{slug} is, that its only for 2 levels. The gandparent and the grand-grand-grandparent are not sluggified with this method. Do u know what to do in this case?
    – Slowwie
    Aug 16, 2020 at 18:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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