Cms: Override max-length on the Title format field

Created on 21 Oct 2019  路  4Comments  路  Source: craftcms/cms

We're using entry properties in the Title format field to automate titles for some channels. However we've ran into the issue of this field having a max-length set on it. I understand why this exists when you create an entry. But when you're setting up the code to auto generate titles you can easily run longer than the allowed 255 characters.

image

Is there a way to change the max length or some way to get around this issue?

We've looked but haven't found any plugins to deal with this issue nor any clever ways to get around the current limitation. I've seen some posts about the max length but they relate to when you add entries. This is just about when you setup automated titles.

question

Most helpful comment

Since Craft 3.3.1 you can actually include a front-end template from that field, which is handy for longer title formats.

So move your current template to something like _formats/bonuses-title.twig.

Note that the { shortcut won鈥檛 exist there so you will need to replace those with proper Twig syntax, and refer to the entry as object. So for example, instead of {partnerSelector.one().title} you would need to do {{ object.partnerSelector.one().title }}.

Once you鈥檝e created that template, replace your current title format with {% include '_formats/bonuses-title' %}.

All 4 comments

Brandon may well have a better idea, but having done something as you
are once before, another way occurs to me.

What if you generate these mammoth 'titles' into a secondary field,
which not being bound up in Craft's internal usages could be set for a
longer length?

You'd then build unique code to stuff into the actual title field, which
surely shouldn't need to take 256 characters.

A late-night thought, anyway.

This solution would mean that we have to copy in the code into that new field every time we add a new entry. So it's not an ideal solution for us. But I still wanted to try it out and I'm sad to say that unfortunately it doesn't work.

But thanks for the suggestion narration-sd. A lot of times the late night thoughts are the best ones!

Since Craft 3.3.1 you can actually include a front-end template from that field, which is handy for longer title formats.

So move your current template to something like _formats/bonuses-title.twig.

Note that the { shortcut won鈥檛 exist there so you will need to replace those with proper Twig syntax, and refer to the entry as object. So for example, instead of {partnerSelector.one().title} you would need to do {{ object.partnerSelector.one().title }}.

Once you鈥檝e created that template, replace your current title format with {% include '_formats/bonuses-title' %}.

Ideally Craft would either: not have a limitation for the title field setup in the back end or have a setting allowing you to override it if you know what you are doing.

But for now, this seems like a viable work around for this issue. Thanks for the help @brandonkelly

Was this page helpful?
0 / 5 - 0 ratings

Related issues

brandonkelly picture brandonkelly  路  3Comments

davist11 picture davist11  路  3Comments

darylknight picture darylknight  路  3Comments

lukebailey picture lukebailey  路  3Comments

angrybrad picture angrybrad  路  3Comments