Skip to main content

String Operators

When we need to work with strings, these operators will help with your markdown.

List of Operators

{{ append }}

Append the specified suffix to the given string.

Params

  • str
  • suffix
  • returns

Example

<!-- given that "item.stem" is "foo" -->
{{append item.stem ".html"}}
<!-- results in: 'foo.html' -->

{{ camelcase }}

camelCase the characters in the given string.

Params

  • string : The string to camelcase.
  • returns

Example

{{camelcase "foo bar baz"}};
<!-- results in: 'fooBarBaz' -->

{{ capitalize }}

Capitalize the first word in a sentence.

Params

  • str
  • returns

Example

{{capitalize "foo bar baz"}}
<!-- results in: "Foo bar baz" -->

{{ capitalizeAll }}

Capitalize all words in a string.

Params

  • str
  • returns

Example

{{capitalizeAll "foo bar baz"}}
<!-- results in: "Foo Bar Baz" -->

{{ center }}

Center a string using non-breaking spaces

Params

  • str
  • spaces
  • returns

{{ chop }}

Like trim, but removes both extraneous whitespace and non-word characters from the beginning and end of a string.

Params

  • string : The string to chop.
  • returns

Example

{{chop "_ABC_"}}
<!-- results in: 'ABC' -->

{{chop "-ABC-"}}
<!-- results in: 'ABC' -->

{{chop " ABC "}}
<!-- results in: 'ABC' -->

{{ dashcase }}

dash-case the characters in string. Replaces non-word characters and periods with hyphens.

Params

  • string
  • returns

Example

{{dashcase "a-b-c d_e"}}
<!-- results in: 'a-b-c-d-e' -->

{{ dotcase }}

dot.case the characters in string.

Params

  • string
  • returns

Example

{{dotcase "a-b-c d_e"}}
<!-- results in: 'a.b.c.d.e' -->

{{ downcase }}

Lowercase all of the characters in the given string. Alias for lowercase.

Params

  • string
  • returns

Example

{{downcase "aBcDeF"}}
<!-- results in: 'abcdef' -->

{{ ellipsis }}

Truncates a string to the specified length, and appends it with an elipsis, .

Params

  • str
  • length : The desired length of the returned string.
  • returns : The truncated string.

Example

{{ellipsis (sanitize "<span>foo bar baz</span>"), 7}}
<!-- results in: 'foo bar…' -->
{{ellipsis "foo bar baz", 7}}
<!-- results in: 'foo bar…' -->

{{ hyphenate }}

Replace spaces in a string with hyphens.

Params

  • str
  • returns

Example

{{hyphenate "foo bar baz qux"}}
<!-- results in: "foo-bar-baz-qux" -->

{{ isString }}

Return true if value is a string.

Params

  • value
  • returns

Example

{{isString "foo"}}
<!-- results in: 'true' -->

{{ lowercase }}

Lowercase all characters in the given string.

Params

  • str
  • returns

Example

{{lowercase "Foo BAR baZ"}}
<!-- results in: 'foo bar baz' -->

{{ occurrences }}

Return the number of occurrences of substring within the given string.

Params

  • str
  • substring
  • returns : Number of occurrences

Example

{{occurrences "foo bar foo bar baz" "foo"}}
<!-- results in: 2 -->

{{ pascalcase }}

PascalCase the characters in string.

Params

  • string
  • returns

Example

{{pascalcase "foo bar baz"}}
<!-- results in: 'FooBarBaz' -->

{{ pathcase }}

path/case the characters in string.

Params

  • string
  • returns

Example

{{pathcase "a-b-c d_e"}}
<!-- results in: 'a/b/c/d/e' -->

{{ plusify }}

Replace spaces in the given string with pluses.

Params

  • str : The input string
  • returns : Input string with spaces replaced by plus signs

Example

{{plusify "foo bar baz"}}
<!-- results in: 'foo+bar+baz' -->

{{ prepend }}

Prepends the given string with the specified prefix.

Params

  • str
  • prefix
  • returns

Example

<!-- given that "val" is "bar" -->
{{prepend val "foo-"}}
<!-- results in: 'foo-bar' -->

{{ raw }}

Render a block without processing mustache templates inside the block.

Params

  • options
  • returns

Example

{{{{#raw}}}}
{{foo}}
{{{{/raw}}}}
<!-- results in: '{{foo}}' -->

{{ remove }}

Remove all occurrences of substring from the given str.

Params

  • str
  • substring
  • returns

Example

{{remove "a b a b a b" "a "}}
<!-- results in: 'b b b' -->

{{ removeFirst }}

Remove the first occurrence of substring from the given str.

Params

  • str
  • substring
  • returns

Example

{{remove "a b a b a b" "a"}}
<!-- results in: ' b a b a b' -->

{{ replace }}

Replace all occurrences of substring a with substring b.

Params

  • str
  • a
  • b
  • returns

Example

{{replace "a b a b a b" "a" "z"}}
<!-- results in: 'z b z b z b' -->

{{ replaceFirst }}

Replace the first occurrence of substring a with substring b.

Params

  • str
  • a
  • b
  • returns

Example

{{replace "a b a b a b" "a" "z"}}
<!-- results in: 'z b a b a b' -->

{{ reverse }}

Reverse a string.

Params

  • str
  • returns

Example

{{reverse "abcde"}}
<!-- results in: 'edcba' -->

{{ sentence }}

Sentence case the given string

Params

  • str
  • returns

Example

{{sentence "hello world. goodbye world."}}
<!-- results in: 'Hello world. Goodbye world.' -->

{{ snakecase }}

snake_case the characters in the given string.

Params

  • string
  • returns

Example

{{snakecase "a-b-c d_e"}}
<!-- results in: 'a_b_c_d_e' -->

{{ split }}

Split string by the given character.

Params

  • string : The string to split.
  • returns character: Default is an empty string.

Example

{{split "a,b,c" ","}}
<!-- results in: ['a', 'b', 'c'] -->

{{ startsWith }}

Tests whether a string begins with the given prefix.

Params

  • prefix
  • testString
  • options
  • returns

Example

{{#startsWith "Goodbye" "Hello, world!"}}
Whoops
{{else}}
Bro, do you even hello world?
{{/startsWith}}

{{ titleize }}

Title case the given string.

Params

  • str
  • returns

Example

{{titleize "this is title case"}}
<!-- results in: 'This Is Title Case' -->

{{ trim }}

Removes extraneous whitespace from the beginning and end of a string.

Params

  • string : The string to trim.
  • returns

Example

{{trim " ABC "}}
<!-- results in: 'ABC' -->

{{ trimLeft }}

Removes extraneous whitespace from the beginning of a string.

Params

  • string : The string to trim.
  • returns

Example

{{trim " ABC "}}
<!-- results in: 'ABC ' -->

{{ trimRight }}

Removes extraneous whitespace from the end of a string.

Params

  • string : The string to trim.
  • returns

Example

{{trimRight " ABC "}}
<!-- results in: ' ABC' -->

{{ truncate }}

Truncate a string to the specified length. Also see ellipsis.

Params

  • str
  • limit : The desired length of the returned string.
  • suffix : Optionally supply a string to use as a suffix to denote when the string has been truncated. Otherwise an ellipsis () will be used.
  • returns : The truncated string.

Example

truncate("foo bar baz", 7);
<!-- results in: 'foo bar' -->
truncate(sanitize("<span>foo bar baz</span>", 7));
<!-- results in: 'foo bar' -->

{{ truncateWords }}

Truncate a string to have the specified number of words. Also see truncate.

Params

  • str
  • limit : The desired length of the returned string.
  • suffix : Optionally supply a string to use as a suffix to denote when the string has been truncated.
  • returns : The truncated string.

Example

truncateWords("foo bar baz", 1);
<!-- results in: 'foo…' -->
truncateWords("foo bar baz", 2);
<!-- results in: 'foo bar…' -->
truncateWords("foo bar baz", 3);
<!-- results in: 'foo bar baz' -->

{{ upcase }}

Uppercase all of the characters in the given string. Alias for uppercase.

Params

  • string
  • returns

Example

{{upcase "aBcDeF"}}
<!-- results in: 'ABCDEF' -->

{{ uppercase }}

Uppercase all of the characters in the given string. If used as a block helper it will uppercase the entire block. This helper does not support inverse blocks.

Params

  • str : The string to uppercase
  • options : Handlebars options object
  • returns

Example

{{uppercase "aBcDeF"}}
<!-- results in: 'ABCDEF' -->