-
Notifications
You must be signed in to change notification settings - Fork 10
Cookbook: MIK's custom Twig extensions
MIK uses the Twig templating engine (version 1.x) in the InsertXmlFromTemplate metadata manipulator Templated metadata parser. It also provides a custom Twig filter, "TwigTruncate". This custom filter will truncate a string to a specific length while respecting word boundaries. One use case for this filter is to truncate object titles within MODS records, since titles longer than 255 characters are problematic in Islandora.
The filter takes one parameter, the length at which to truncate the string. TwigTruncate will truncate the string at the specified length or at the nearest preceding word boundary. An example of its use within a Twig template is:
{% if Title|length < 255 %}
<titleInfo>
<title>{{ Title }}</title>
</titleInfo>
{% else %}
<titleInfo>
<title>{{ Title|TwigTruncate(249) }} [...]</title>
</titleInfo>
{% endif %}
Content on the Move to Islandora Kit wiki is licensed under a Creative Commons Attribution 4.0 International License.