Widont is a twig filter that prevent widow words in paragraphs.
It replaces the space between the last word(s) in a string with
.
It works in these block tags (h1-h6, p, li)
, and also accounts for these potential closing inline elements a|span|i|b|em|strong|acronym|caps|sub|sup|abbr|big|small|code|cite|tt
.
To install Widont, follow these steps:
- Download & unzip the file and place the
widont
sub-directory into yourcraft/plugins
directory - Install plugin in the Craft Control Panel under Settings > Plugins
Widont works on Craft 2.5.x.
{{ someRichText | widont }}
- Words [Number = 1] - Number of words to force break
- Raw [Bool = true] - Return raw output via TemplateHelper::getRaw()
The following:
{{ <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit.</p> | widont }}
output this:
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit.</p>
But you can also control how many words to force break
:
{{ <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit.</p> | widont(2) }}
output this:
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit.</p>
Widont php implementation taken from TypogrifyHelper for CakePHP.
Spider Web icon by Muhamad Ulum from the Noun Project.
- Initial release
Brought to you by Alexander Bech