DH
David Hellmann
2019/12/14

Craft CMS — Dynamic Title Formats

One of my favorite features in Craft CMS is the possibility to create dynamic titles. I think it's currently just possible to use this for entries but that's fine. For a few months we use entries for all, also for categories, and so on. Brandon mentioned in one of the GitHub Issues that it comes all together in the futures within the Content menu item. I'll replace the entries menu item. However, we are here to speak about dynamic titles.

What are dynamic titles

In craft, an entry needs at least a title. Most of the time, you as the author write something in the title field and it's fine. But imagine you have a lot of content and then in the future, the content grows and grows. Many authors work on the content and sometimes you have content where you need a strict naming for titles or a certain structure for the title. You can do that all the time by hand but that does not fail-proof. With dynamic titles, you have the possibility to make life much easier for your authors or just for yourself. Sometimes you have nothing to write by hand. And sometimes you pick just some related entries from which the title will create.

How it works

Let's get away with this… We have some products. The product has a product category, a title, and an Id / SKU Number. Now, when you create a product entry you have to write this in the title field: Product Category - Product Title - SKU Number. It's easy you think but is it? I think no. So here comes the dynamic title into play. Someone was thinking about how the title is structured. Suppose we need to get to the three things from above also a namespace. Now our finale title format looks like this: P - category - product title - SKU — yes, that looks fine. We have a P what is the Namespace and stands simply for Products. Second is the category title, third the product title and the last one, that's the SKU. But how comes this to a dynamic title? Craft has a powerful control panel. You can put some twig logic in many of the input fields to make the stuff dynamic. In our case, we have three fields from which we create the title later. This looks like this: P - {productsCategory.one().title} - {productsTitle} - {productsId}

This is the product entry type

Craft Cms Dynamic Titles 01

This is our product entry

As you see, there is a Products ID field what is our Id / SKU. Below we have our Product title field what is just the product name. Below the title comes the Products Category field. From these three fields and the namespace, we build our title.

Craft Cms Dynamic Titles 02

Now, our product overview looks like this:

Craft Cms Dynamic Titles 03

Or for our product advantages it looks like this:

Craft Cms Dynamic Titles 04

You can see, that you have a clean title for each item. And a positive side effect is that you have disjoined your long title into short pieces and this gives you the possibility to change your entire title format in the future very easily.

I'm a big fan of title generation like this and I/we use it more and more.

What do you think about it? Any use cases for this in the future? Give it a try, it's awesome!

comments powered by Disqus

Maybe interesting…

UP