Guide
Casing & Capitalization
Wordsmith provides several methods for case modification:
apTitleize
camelize
dasherize
entitle
humanize
hyphenate
pascalize
slugify
titleize
underscore
underscored
upperCamelize
Case Modification
apTitleize
Intelligently up-cases a string as a headline/title using AP capitalization rules.
{{ 'a tale of two cities' | camelize }} |
camelize
Returns a camelCase version of the string.
Trims surrounding spaces, capitalizes letters following digits, spaces, dashes and underscores, and removes spaces, dashes, as well as underscores.
{{ 'Camel-Case' | camelize }} |
dasherize
Returns a lowercase and trimmed string separated by dashes.
Dashes are inserted before uppercase characters (with the exception of the first character of the string), and in place of spaces as well as underscores.
{{ 'fooBar' | dasherize }} |
entitle
Alias for apTitleize
.
Provided so that Wordsmith can be a drop-in replacement for the Entitle plugin.
humanize
Capitalizes the first word of the string, replaces underscores with spaces, and strips away an ‘_id’ suffix if one is present.
{{ 'author_id' | humanize }} |
{{ 'some_snake_case_words' | humanize }} |
hyphenate
Alias for dasherize
.
Provided so that Wordsmith can be a drop-in replacement for the Inflect and Typogrify plugins.
pascalize
Alias for upperCamelize
.
Provided so that Wordsmith can be a drop-in replacement for the Inflect and Typogrify plugins.
slugify
Converts the string into an URL slug.
This includes replacing non-ASCII characters with their closest ASCII equivalents, removing remaining non-ASCII and non-alphanumeric characters, and replacing whitespace with $replacement. The replacement defaults to a single dash, and the string is also converted to lowercase. The language of the source string can also be supplied for language-specific transliteration.
{{ 'Using strings like fòô bàř' | slugify }} |
titleize
Returns a trimmed string with the first letter of each word capitalized.
Also accepts an array, $ignore, allowing you to list words you want to leave un-capitalized.
ignore
(default provided in config) — Array of words to ignore when capitalizing
{{ 'i like to watch television' | titleize }} |
If you’re working with titles in English, you may also be interested in apTitleize
, which is a bit more intelligent and follows AP title capitalization rules.
underscore
Returns a lowercase and trimmed string separated by underscores.
Underscores are inserted before uppercase characters (with the exception of the first character of the string), and in place of spaces as well as dashes.
{{ 'TestACase' | underscored }} |
underscored
Alias for underscore
.
Provided for compatibility with Stringy, so that Wordsmith can be a drop-in replacement for the Typogrify plugin.
upperCamelize
Returns an UpperCamelCase version of the supplied string.
It trims surrounding spaces, capitalizes letters following digits, spaces, dashes and underscores, and removes spaces, dashes, underscores.
{{ 'Upper Camel-Case' | upperCamelize }} |