Liking cljdoc? Tell your friends :D

Functions

You can call functions from within the template files and embed the call result easily by writing {%=functionName(arg1, arg2, arg3, ...)%} expression in the document template.

This is a short description of the functions implemented in Stencil.

Basic Functions

Coalesce

Accepts any number of arguments, returns the first not-empty value.

Exampe:

  • to insert the first filled name value: {%=coalesce(partnerFullName, partnerShortName, partnerName)%}
  • to insert the price of an item or default to zero: {%=coalesce(x.price, x.premium, 0)%}

Empty

Decides if a parameter is empty or missing. Useful in conditional statements.

Example:

{%if empty(userName) %}Unknown User{%else%}{%=userName%}{%end%}

If the value of userName is missing then Unknown User will be inserted, otherwise the value is used.

The empty() function is useful when we want to either enumerate the contents of an array or hide the whole paragraph when the array is empty.

String functions

These functions deal with textual data.

Format

Calls String.format function.

Example:

This example formats the value of price as a price string: {%=format("$ %(,.2f"", price) %}. It may output $ (6,217.58).

Date

Formats a date value according to a given format string.

Arguments:

  1. First argument is a format string.
  2. Second argument is a string containing a date value.

Example:

This example formats the value of partner.birthDate as a date string: {%=date("yyyy-MM-dd", partner.birthDate) %}

Also, try these formats strings:

  • "yyyy-MM-dd HH:mm:ss" for example: 2018-02-28 13:01:31
  • "EEE, dd MMM yyyy HH:mm:ss zzz" (also known as RFC1123)
  • "EEEE, dd-MMM-yy HH:mm:ss zzz" (a.k.a. RFC1036)
  • "EEE MMM d HH:mm:ss yyyy" (ASCTIME)
  • "yyyy-MM-dd'T'HH:mm:ss.SSSXXX" (ISO8601)

Can you improve this documentation?Edit on GitHub

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close