Custom URL based on Categories I am very new to this CMS and I was able to set it up, import some content from csv files.

I have set up templates and right now if someone clicks on the article, the URL is www.example.com/articles/{slug} of the article. This is all fine if I wasn't migrating from another system and we have a ton of articles and the URL was based on SEO requirements.

I have set up a channel type and one of the fields is Category type. I have 2 more category type fields but I don't use them to create the URL. 

Here is the screenshot of what it looks like

A lot of content from olden days doesn't have the second category (so would just belong to Analog/ Mixed Signal ICs) but the newer content (from last 3 odd years most likely has it). So when the Url is display I want the URL to be either www.example.com/Analog_Mixed_Signal_ICs/Title
or 
www.example.com/Analog_Mixed_Signal_ICs/Amplifiers/Title

I am not sure if this simple or complex but I would appreciate if someone can tell me how to achieve this.
I wouldn't normally set up a site like this — but given your setup, the following should work.


In the category settings, make sure that your category has 'Entries in this section have their own URLs' checked.
Set your category url format to:


top-level: {slug}
nested categories: {parent.uri}/{slug}

Set your article entry url format in the channel settings to {category.last.uri}/{slug} (where 'category' is the handle of your category field.)


Note the use of last. Categories will be returned as an Element Criteria Model which behaves much like an array (even if there is only one defined). The use of last will return the last category element, which should be the uri pattern that you're looking for.

Of course, if you have other routes in the CMS you will have to be careful about routing conflicts.

As a side note, you might want to consider using a 'structure' instead of 'categories'. I commonly use a single structure that represents all of the top level pages in a site, using Entry Types to distinguish the various field requirements and page layouts. You can then include the appropriate template layout automatically based on 'entry.type'. Likewise, you can use this structure to easily generate your site nav, and be fairly confident you won't run into any routing conflicts. The only reason I mention this is that you seem to already be heading in this direction with your current setup.

Edit: I might also add that you will want to make your category field required, otherwise there will be no route to the article in question.