Skip to content

Cookbook: Dealing with titles longer than 255 characters

Mark Jordan edited this page Mar 30, 2017 · 2 revisions

Fedora Commons enforces a maximum length of 255 characters on its object labels. In Islandora, the label comes from the MODS <title> element. When an object whose label exceeds 255 characters is ingested, Islandora silently truncates it at the 255th character.

To work around this, you can use a Twig template via the MIK InsertXmlFromTemplate metadata manipulator to truncate the length of the value used in the MODS <title> element and add an ellipsis in the title a few characters short of 255:

{% if Title|length < 256 %}
  <titleInfo>
     <title>{{ Title|trim }}</title>
  </titleInfo>
{% else %}
  <titleInfo>
     <title>{{ Title|TwigTruncate(200) | trim }} [...]</title>
  </titleInfo>
{% endif %}

The InsertXmlFromTemplate manipulator provides a Twig extension to truncate a string at the nearest word boundary, so you don't get half-words at the end of your title.

Cookbook table of contents

Clone this wiki locally