Skip to content

<xmod:Format>

<xmod:Format> takes a value (typically a [[FieldName]] token) and reformats it for display: numbers and dates get formatted to a culture-aware pattern, text gets String.Format-style placeholder substitution, regular expressions get replaced, and HTML or URL content gets encoded or decoded.

It's a self-closing tag — supply the value via the Value attribute, or place it between the opening and closing tags when the value contains characters that confuse attribute delimiters (single or double quotes).

Example

html
<xmod:Template ...>
  <ItemTemplate>
    <!-- Floating-point with leading zero, two decimals: 5 → 05.00 -->
    Price (2dp): <xmod:Format Type="Float" Value="[[Price]]" Pattern="0#.00" />

    <!-- Whole number, two digits: 5 → 05 -->
    Quantity: <xmod:Format Type="Numeric" Value="[[Quantity]]" Pattern="d2" />

    <!-- Currency formatted in the server's culture: 5 → $5.00 (US) or £5.00 (UK) -->
    Price: <xmod:Format Type="Float" Value="[[Price]]" Pattern="c" />

    <!-- Currency forced to UK formatting on every server -->
    Price (UK): <xmod:Format Type="Float" Value="[[Price]]" Pattern="c" OutputCulture="en-GB" />

    <!-- Date: 04/25/2013 → 04/25/2013 -->
    Date: <xmod:Format Type="Date" Value="[[ReleaseDate]]" Pattern="MM/dd/yyyy" />

    <!-- Email cloaked from spam bots -->
    Contact: <xmod:Format Type="Cloak" Value="[[Email]]" />
  </ItemTemplate>
</xmod:Template>

Properties

PropertyValuesDefaultDescription
Type *Numeric Float Date Text RegEx Cloak HtmlEncode HtmlDecode UrlEncode UrlDecodeWhat kind of formatting to perform
Valuestring | tokenThe value to format. Alternatively, place between the opening and closing tags
Patternformat stringPattern used for Numeric, Float, Date, and RegEx types
ReplacementstringReplacement values used for Text and RegEx types
MaxLengthinteger0 (no limit)Truncate the formatted output to N characters and append an ellipsis. Ignored when Type="Cloak"
InputCulturelocale id(current culture)Culture used to parse Value (e.g. for non-US date formats)
OutputCulturelocale id(current culture)Culture used to format the output

* Required property

Property Details

  • Type: How the value is interpreted and formatted.

    TypeValue treated asPattern + Replacement
    NumericWhole number.NET integer format string (d, d2, n, c, custom)
    FloatFloating-point number.NET numeric format string (0.00, c, g, custom)
    DateDate/time.NET date format string (MM/dd/yyyy, ddd MMM dd yyyy, custom)
    TextComposite format string with {0}, {1}, … placeholdersReplacement is a comma-delimited list of values to fill the placeholders
    RegExSubject string for a regex replacePattern is the match regex; Replacement is the replacement (with $1, $2, … back-references)
    CloakEmail or other string to obfuscate from spam bots(no pattern — uses DNN's CloakText JavaScript obfuscator)
    HtmlEncode / HtmlDecodeText to HTML-encode or decode(no pattern)
    UrlEncode / UrlDecodeText to URL-encode or decode(no pattern)

    Cloak caveat

    Cloak uses inline JavaScript to assemble the value at render time. If JavaScript is disabled, the cloaked text doesn't appear at all. It also can't be used inside a mailto: link, since the href is parsed before the script runs.

  • Value: The value to format. Either as the Value attribute or as the inner content of the tag — useful when the value contains both single and double quotes that would conflict with attribute delimiters.

    html
    <xmod:Format Type="Text">[[QuotedField]]</xmod:Format>
  • Pattern: The format pattern. Meaning depends on Type:

    TypePattern is
    Numeric / FloatA .NET numeric format string — e.g. 0, 00, 0.00, c (currency), n (number with separators), g (general)
    DateA .NET date format string — e.g. MM/dd/yyyy, dddd MMMM d, yyyy
    TextNot used — the placeholders are inside Value itself
    RegExThe regular expression to match in Value
  • Replacement: Replacement payload. Meaning depends on Type:

    TypeReplacement is
    TextComma-delimited list of values that fill {0}, {1}, … inside Value
    RegExThe replacement string for the regex, with $1, $2, … back-references
    otherIgnored

    Text example — Value="Hello {0}, How's the {1}?", Replacement="John,weather""Hello John, How's the weather?"

  • MaxLength: When greater than 0, truncates the formatted output to that many characters and appends .... The ellipsis is included in the count, so MaxLength="10" produces at most 10 characters total. Ignored for Cloak because truncating obfuscated text can break the unscrambling.

  • InputCulture / OutputCulture: Locale identifiers (e.g. en-US, fr-FR, de-DE) used when parsing or formatting culture-sensitive values like dates and numbers.

    UseExample
    Parse a French-formatted date as inputInputCulture="fr-FR"
    Render currency in UK pounds regardless of serverOutputCulture="en-GB" Pattern="c"`
    BothTake a US date and display it French-style — InputCulture="en-US" OutputCulture="fr-FR"

    Use invariant for culture-neutral formatting.