The Format
tag takes given content and applies various types of formatting to it.
Example
<Format length=60>
<Field description />
</Format>
The above will trim the field value to maximum length of 60 characters.
Case
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
.
Code
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.
Date
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.
Examples
<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
.
Length
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.
Number
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 thousands
Replace
Use 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="-" />
Multiple replaces
To replace multiple different texts, use:
replace_2
andwith_2
replace_3
andwith_3
URL
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>