silverbullet/website/Functions.md

1.5 KiB
Raw Blame History

Here is a list of all functions you can use in SilverBullets Expression Language:

Lists

count(list)

Count the number of elements in a list:

There are **{{count({page})}}** pages in this space.

at(list, index)

Returns the indexth element of list (starting from 0 of course).

Index 1 of our count to three is {{at([1, 2, 3], 1)}}

Templates

template(text, value)

Renders a template with an optional value:

{{template([[Library/Core/Query/Page]], {"name": "Some page"})}}

Date and time

today()

Todays date in a YYYY-MM-dd format.

tomorrow()

Tomorrows date in a YYYY-MM-dd format.

yesterday()

Yesterdays date in YYYY-MM-dd format.

niceDate(timestamp)

Convert a unix timestamp to a YYYY-MM-dd format.

time()

Current time.

String manipulation

replace(str, match, replacement)

Replace text in a string. match can either be a literal string or a regular expression: replace("hello", "ell", "all") would produce “hallo”, and replace("hello", /l/, "b") would produce “hebbo”.

json(obj)

Convert the argument to a JSON string (for debugging purposes).

The current page object: {{json(@page)}}

Space related

pageExists(name)

Checks if the page name exists:

This very page exists: {{pageExists(@page.name)}}

And this one: {{pageExists("non-existing")}}

readPage(name)

Reads in the content of the page name and returns it as a string.