Format.crop ViewHelper <f:format.crop>
ViewHelper which can crop (shorten) a text. Whitespace within the <f: element will be counted as characters.
Go to the source code of this ViewHelper: Format\CropViewHelper.php (GitHub).
Table of contents
Examples
Defaults
packages/my_extension/Resources/Private/Templates/Content/Text.fluid.html
<f:format.crop maxCharacters="10">
This is some very long text
</f:format.crop>
Copied!
Output
This is...
Copied!
The third word "some" does not fit in the 10 character limit, because respectWordBoundaries is true by default.
Custom suffix
packages/my_extension/Resources/Private/Templates/Content/Text.fluid.html
<f:format.crop maxCharacters="17" append=" [more]">
This is some very long text
</f:format.crop>
Copied!
Output
This is some [more]
Copied!
Don't respect word boundaries
packages/my_extension/Resources/Private/Templates/Content/Text.fluid.html
<f:format.crop maxCharacters="10" respectWordBoundaries="false">
This is some very long text
</f:format.crop>
Copied!
Output
This is s...
Copied!
Don't respect HTML tags
packages/my_extension/Resources/Private/Templates/Content/Text.fluid.html
<f:format.crop maxCharacters="28" respectWordBoundaries="false" respectHtml="false">
This is some text with <strong>HTML</strong> tags
</f:format.crop>
Copied!
Output
This is some text with <stro
Copied!
Inline notation
packages/my_extension/Resources/Private/Templates/Content/Text.fluid.html
{someLongText -> f:format.crop(maxCharacters: 10)}
Copied!
Output
someLongText cropped after 10 characters…
Copied!
Depending on the value of {some.
Arguments of the <f:format.crop> ViewHelper
append
-
- Type
- string
- Default
- '…'
What to append, if truncation happened
maxCharacters
-
- Type
- int
- Required
- 1
Place where to truncate the string
respectHtml
-
- Type
- bool
- Default
- true
If TRUE the cropped string will respect HTML tags and entities. Technically that means, that cropHTML() is called rather than crop()
respectWordBoundaries
-
- Type
- bool
- Default
- true
If TRUE and division is in the middle of a word, the remains of that word is removed.