Format

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.

  • camel - Example: camelCase
  • kebab - Example: kebab-case
  • snake - Example: snake_case
  • pascal - Example: PascalCase

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 &amp; 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: 2021-10-19.

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: mardi 19 octobre 2021.

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 display
  • point - Character for decimal point
  • thousands - 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="-" />