The Format
tag takes given content and applies various types of formatting to it.
<Format length=60>
<Field description />
</Format>
The above will trim the field value to maximum length of 60 characters.
Use the case
attribute to convert to the following cases.
Case | Example |
camel
|
camelCase
|
kebab
|
kebab-case
|
snake
|
snake_case
|
pascal
|
PascalCase
|
lower
|
lowercase
|
upper
|
UPPERCASE
|
For example, this:
<Format case=kebab>Hello, world</Format>
..will output: hello-world
.
Use the code
attribute to escape text for inline <code>
, or <pre>
block.
<Format code>this & that</Format>
..will output: this & that
.
It uses PHP's htmlspecialchars function.
Use the date
attribute to apply date formatting.
It uses the excellent Carbon date/time library.
See the Date tag for details on formatting and additionally supported attributes.
<Format date="Y-m-d">today</Format>
..will output: 2022-07-18
.
Use date=default
to use the site setting from Settings -> General -> Date Format.
<Format date="l j F Y" locale=fr>today</Format>
..will output: lundi 18 juillet 2022
.
Use the length
attribute to limit to a maximum length of characters.
<Format length=60>
<Field description />
</Format>
It uses PHP's mb_substr function, which supports UTF-8 multibyte characters.
Use the number
attribute to format numbers.
<Format number decimals="2" point="," thousands=".">1000000</Format>
..will output: 1.000.000,00
It uses PHP's number_format function.
Optional attributes are:
decimals
- Number of decimal places to displaypoint
- Character for decimal pointthousands
- Character for separating thousandsUse the replace
and with
attributes to replace pieces of text.
<Format replace=" " with="-">555 555 5555</Format>
The above example results in 555-555-5555
.
The same attributes are supported in Field
tag.
<Field phone_number replace=" " with="-" />
To replace multiple different texts, use:
replace_2
and with_2
replace_3
and with_3
Use the remove_html
attribute to strip content of all HTML tags. For example, the template below would output 12345
.
<Format remove_html>
<a href="example.com">123</a><script>alert("hi")</script><b>456</b>
</Format>
Use the start_slash
or end_slash
attributes to ensure that a URL or string has a starting or ending slash. Use start_slash=false
or end_slash=false
to remove the starting or ending slash. For example, the following template would output example/
:
<Format start_slash=false end_slash>/example/</Format>
This can be helpful when working with URLs, as shown below.
<a href="{Format end_slash=false}{Field url}{/Format}/child-page">Child page</a>
slug
attribute to strip out HTML tags, convert to lowercase, remove special characters, and replace spaces with dashes. For example, the template below would output this-is-a-simple-string
.<Format slug>This is a <em>simple</em> string!</Format>
Use format url_query
to encode URL query string.
<Format url_query>?key=value with some spaces</Format>
Usually, this is passed to a link href
attribute. It's probably easier to set it to a variable first.
<Set q><Format url_query>..</Format></Set>
<a href="https://example.com{Get q}"></a>