TransWikia.com

Dynamic URL generated by a custom field dropdown value

Craft CMS Asked by Hopstad on December 25, 2020

I have a special case where the URL needs to be defined from within the entry itself. I have a dropdown that I want to populate with the URLs as values.

Can the dropdown value be used to generate the URL? I can not use custom site URLs because the customer/user needs to see the URL themselves from within the entry.

The entry is a channel.

So let’s say the dropdown has a label called "Monkey". Then I want the URL to be /monkey/article-slug.

One Answer

In the section settings, you can specify a dynamic entry URI format.

As the docs say, this box is in fact a mini Twig template, and is preloaded with the element being saved (accessible as object) and its custom fields (accessible directly by their handles). Good to know that you can also use a shortcut syntax with single braces instead of double ones here.

So in your case you'd want something like:

{slugPrefixFieldHandle ? slugPrefixFieldHandle ~ '/' ~ slug : slug}

Correct answer by James Smith on December 25, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP