Plugin for Craft CMS which adds an inflection twig extension.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
inflect
.gitignore
InflectPlugin.php reorganise repo Jun 22, 2016
composer.json reorganise repo Jun 22, 2016
composer.lock Refactor structure to allow project to be required using composer Feb 25, 2016
readme.md

readme.md

Inflection Craft Plugin

This plugin enables a several Twig filters to transform the inflection of strings using the following methods:

  • pluralize
  • singularize
  • camelize
  • dasherize
  • pascalize
  • titleize
  • underscore
  • humanize
  • hyphenate
  • ordinalize
  • slugify

Craft 2 Only

Most of the above filters are now already available in Craft 2 and 3. See the chart below for the mapping:

Inflect Craft 2 Craft 3
pluralize Try the Typogrify plugin
singularize Try the Typogrify plugin
camelize camel camel
dasherize kebab kebab
pascalize pascal pascal
titleize ucwords or title ucwords or title
humanize Try the Typogrify plugin
hyphenate Try the Typogrify plugin
ordinalize Try the Typogrify plugin
slugify Try the Typogrify plugin

The Typogrify plugin allows you to use all of the Stringy package features on your strings.

Download

This github project is for developers using composer to require dependencies. Do not download the zip from github, but download on the releases page.

Usage Examples

{{ 'bum'|pluralize(3) }} # bums
{{ 'person'|pluralize }} # people
{{ 'people'|pluralize(1) }} # person
 {% set entries = craft.entries.find() %}
 {% set size = entries|length %}
 You have: {{ size }} {{ 'entry'|pluralize(size) }} # You have: 3 entries
 The {{ size|ordinalize }} entry # The third entry
{{ 'My string to inflect'|slugify }} # my-string-to-inflect
{{ 'my-string-to-inflect'|camelize }} # myStringToInflect
{{ 'myStringToInflect'|underscore }} # my_string_to_inflect
{{ 'my_string_to_inflect'|dasherize }} # my-string-to-inflect
{{ 'my-string-to-inflect'|pascalize }} # MyStringToInflect
{{ 'MyStringToInflect'|hyphenate }} # my-string-to-inflect
{{ 'my-string-to-inflect'|titleize }} # My String To Inflect
{{ 'My String To Inflect'|slugify|camelize }} # myStringToInflect

MIT Licence

Original Author Luke Holder Contributors: Tim Kelty