I am auto-generating entry titles based on a plain text field. Now, I would like to limit the characters the title contains of (e.g. 50 chars while the plain text field has 500 chars). How could I do that?

Thank you very much for your help.

up vote 7 down vote accepted

You can use any Twig in the dynamic title field. There are plugins that provide Twig filters to truncate text, but here’s how you can do simple truncation without any plugin.

{{ object.myTextField|length > 50 ? object.myTextField|slice(0, 50) ~ '...' : object.myTextField }}
  • Great, thank you very much! – MISC Jun 30 '16 at 18:41

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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