-
-
Save nternetinspired/03b56e50822ea65f9bf0da89a7dd6602 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% macro truncate(text, limit, append) %} | |
{# settings #} | |
{% set suffix = append|default('...') %} | |
{% set punctuation = ['.',',','-',':',';'] %} | |
{# logic #} | |
{% set array = text|split(' ') %} | |
{% set arrayTruncated = array|slice(0, limit) %} | |
{% set string = arrayTruncated|join(' ') %} | |
{% if limit and array|length > limit %} | |
{% for mark in punctuation %} | |
{% set string = string|trim(mark) %} | |
{% endfor %} | |
{% set string = string ~ suffix %} | |
{% endif %} | |
{{ string }} | |
{% endmacro %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment