silverbullet/website/Functions.md

80 lines
1.9 KiB
Markdown
Raw Normal View 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:
```template
There are **{{count({page})}}** pages in this space.
```
## at(list, index)
Returns the `index`th element of `list` (starting from 0 of course).
```template
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
{{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”.
2024-02-23 20:47:27 +08:00
This function supports an infinite number of replacements, so you can keep adding more, e.g. `replace(str, match1, replacement1, match2, replacement2, match3, replacement3)`
2024-03-02 18:01:52 +08:00
## contains(str, substr)
Returns whether `str` contains `substr` as a substring.
## json(obj)
Convert the argument to a JSON string (for debugging purposes).
```template
The current page object: {{json(@page)}}
```
## yaml(obj)
Convert the argument to a YAML string (for debugging purposes).
```template
The current page object:
~~~yaml
{{yaml(@page)}}
~~~
```
# Space related
## pageExists(name)
Checks if the page `name` exists:
```template
This very page exists: {{pageExists(@page.name)}}
And this one: {{pageExists("non-existing")}}
```
2024-02-06 03:12:46 +08:00
## readPage(name)
Reads in the content of the page `name` and returns it as a string.