5

Simple use case: I have a channel that is setup solely to be used in an entries field to relate goals that are used on multiple pages. The goals channel simply has the title field, as the goals themselves are all one sentence statement and need to be easily identifiable by content editors for the site. Unfortunately, one of them is 268 characters, and the Title field has a limit of 255 characters.

So my question is - is there a recommended way to change the character limit for the title field? If it's in the database structure, where is it? (I will continue to dig through the database for this). If it's in config, is there a configuration override to do this so it doesn't get changed back every update, or a plugin?

Thanks!

2

The title column in the craft_content database table has the column type VARCHAR, which is limited to 255 characters. There's no setting that'll change the column type for you – you can always use a tool like phpMyAdmin or Sequel Prop to change it to TEXT in order to increase the limit and it'll probably work, though it seems like a bit of a risk.

Edit: Brought to my attention by the OP in the comments below that both the actual input field and possibly some validation functionality is also limiting the title field to 255 characters. My revised TLDR answer: Nope, don't bother trying :)

In my opinion, the following would probably be a safer/better way to solve your issue:

  1. Add a PlainText field to your Entry Type (give the handle text or the like). Consider making it multiline, since there's a fair amount of text for each entry.
  2. Pop into the Entry Type's settings (under CP -> Settings -> Sections -> [entry type], and uncheck the Show the Title field checkbox.
  3. In the Title Format field that appears, add something like this:

{{ object.text | length > 252 ? object.text | slice(0, 252) ~ '...' : object.text }}

With the above in place, your content editor(s) will still only have to edit a single field (it'll just be called Text instead of Title), and the contents of the "Text" PlainText field will be copied over to the actual Title field when the entry is saved. For the few entries that have more than 255 characters, the title will be truncated to the first 252 characters, suffixed w/ ... – those 252 characters should probably be enough to identify each entry inside the CP (you might want to add fuzzy searching, btw), and the dots look nicer than just cutting the text off. The text field will contain the full, un-truncated text.

Obviously, in your templates you'll need to use {{ entry.text }} instead of {{ entry.title }} to get the full text.

  • 1
    Thanks. I did find it in the database. However there's also a _titlefield template that limits the input to a maxlength of 255 and appears to be a validation rule that also limits it to 255 characters on submit. So I will try your solution. I agree, 252 characters should be enough to identify most of them, since I was already about 50 goals in before I ran into the problem. Thanks! – Tiffany Ring Nov 9 '17 at 19:37
  • Aha. Didn't think about that; but it kind of drives home the fact that you don't really want to mess around w/ the Craft internals; especially not when there's functionality in there to essentially use any custom field as a title (the Title Format field eats Twig for lunch), and yeah – 255 (or 252) should be enough to identify specific posts, probably :) – Mats Mikkel Rummelhoff Nov 9 '17 at 19:41
  • You seem to be saying that the maximum length of any VARCHAR column is 255 characters. It may be that the current length is set to that but don't believe that's the technical limit. – AllInOne Nov 9 '17 at 19:53
  • @AllInOne you're right, sort of -> stackoverflow.com/a/13506920/4663184. – Mats Mikkel Rummelhoff Nov 9 '17 at 20:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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