helpers /  Strings

Strings

{{lowercase}}

Turns a string to lowercase.
Parameters: none

{{lowercase "MAKE THIS ALL LOWERCASE"}}

Renders to:

make this all lowercase

{{capitalizeEach}}

Capitalizes each word in a string.
Parameters: none

{{capitalizeEach "capitalize EACH word in this sentence"}}

Renders to:

Capitalize EACH Word In This Sentence

{{center}}

Centers a string using non-breaking spaces.
Parameters: spaces: int - The number of spaces. (Required)

{{center "Bender should not be allowed on tv." 10}}

Renders to:

|              Bender should not be allowed on tv.              |

{{dashify}}

Same as hyphenate, but replaces dots in string with hyphens.
Parameters: none

{{dashify "make.this.all.hyphenated"}}

Renders to:

make-this-all-hyphenated

{{formatPhoneNumber}}

Output a formatted phone number

Credit: Treehouse Blog

Data:

number: 4444444444 

Template:

{{formatPhoneNumber number}}

Renders to:

(444) 444-4444

{{hyphenate}}

Replace spaces in string with hyphens.
Parameters: none

{{hyphenate "make this all hyphenated"}}

Result:

make-this-all-hyphenated

{{capitalizeFirst}}

Capitalizes the first word in a string.
Parameters: none

{{capitalizeFirst "capitalize first word in this sentence"}}

Renders to:

Capitalize first word in this sentence

{{occurrences}}

Evaluate string A, and count the occurrences of string B within string A
Default: undefined
Parameters:

  • String A (required): The string to evaluate
  • String B (required): The string to look for and count in "string A"
{{occurrences "evaluate this string" "i"}}

Result:

2

{{reverse}}

Reverses a string.
Parameters: none

{{reverse "bender should NOT be allowed on TV."}}

Renders to:

.VT no dewolla eb TON dluohs redneb

{{sentence}}

Capitalizes the first word of each sentence in a string and converts the rest of the sentence to lowercase. Parameters: none

{{sentence "capitalize the FIRST word in each sentence. but make the OTHER words lowercase."}}

Renders to:

Capitalize the first word in each sentence. But make the other words lowercase.

{{titleize}}

Capitalizes all words within a string. Taken from the templating library Walrus by Jeremy Ruppel.
Parameters: none

{{titleize "capitalize EACH word in this sentence"}}

Renders to:

Capitalize Each Word In This Sentence.

{{truncate}}

Truncates a string given a specified length, providing a custom string to denote an omission.
Parameters:

  • length: int- The number of characters to keep (Required).
  • omission: string - A string to denote an omission (Optional).
{{truncate "Bender should not be allowed on tv." 31 "..."}}

Renders to:

Bender should not be allowed...

{{uppercase}}

Turns a string to uppercase. Opposite of {{lowercase}}.
Parameters: none

 {{uppercase "make this all uppercase"}}

Renders to:

MAKE THIS ALL UPPERCASE

See the template for this page →

Find an error? Let us know →