fastn
has support for rich data modelling, and it supports
declaring variables.
-- integer x: 20
type
s.The data type is mandatory while declaring a variable in fastn
.
fastn
. In other words, the
variable's value cannot be changed once a value is bound to a variable name.-- integer x: 10
-- ftd.integer: $x
$on-click$: $ftd.increment($a = $x)
Cannot have mutable reference of immutable variable `x`
x
. This is one of the many ways fastn
allows
programmers to write code and takes advantage of the safety.Variables are immutable by default. Prefix the variable name with $
to make it
mutable. The value of a mutable variable can be changed.
-- integer $x: 10
-- ftd.integer: $x
$on-click$: $ftd.increment($a = $x)
10
.A variable can be defined as referring to another variable using $
as a prefix
of referenced variable, $<referenced variable>
. This means if the referenced
variable get changed the referer will change too.
When you define a variable in fastn
, you can make it refer to another variable
by adding a $
sign before the referenced variable's name, like $<referenced variable>
. This basically means that if the referenced variable gets updated
or changed, the referring variable will also change accordingly.
x
with a value of
10
, and you define another integer variable called y
with $x
as its value.
Now, y
is the referring variable and x
is the referenced variable. So, if
you update or change the value of x
, the value of y
will also change.-- integer $x: 10
-- integer y: $x
-- ftd.integer: $x
-- ftd.integer: $y
-- ftd.text: I change x
$on-click$: $ftd.increment($a = $x)
x
and y
change together!-- integer x: 10
-- integer y: *$x
-- ftd.text: I change x :)
$on-click$: $ftd.increment($a = $x)
Here, if x changes, y doesn't changes.
The output will be as shown below: Click onI change x :)
to see the result.Once a mutable
variable has been defined it can be updated too.
Any variable can be made mutable
by prefixing it with $
.
fastn variables
are immutable
(can't be changed once
initialized).-- integer $x: 10
-- $x: 20
$processor$
: dynamic variablesfastn
documents are processed in the context of a "platform", and platform can
provide access to dynamic variables.
os
, which is the operating system
on which this document is getting rendered, you can use that like this:-- string name-of-os:
$processor$: os
type
is mandatory when using $processor$
. Available processors would be
documented as part of platform documentation.
-- string greeting: hello, world
$processor$: uppercase
uppercase
, which takes the current
value, hello, world
and returns its upper case value. In this case the variable
greeting will hold the value: HELLO, WORLD
.Like $processor$
, the platform provides foreign variables against a module.
The fastn
stuck itself to fetch value of foreign value, which is, then,
provided by platform.
assets
.-- import: module/assets
-- ftd.text: Check bar content
link: $assets.files.some-folder.bar.ftd
The files
field in assets
variable gives url to files present in package.
So, $assets.files.some-folder.bar.ftd
returns url of
<path-to-package>/some-folder/bar.ftd
as value.
-- import: module/assets
-- ftd.image:
src: $assets.files.images.my-image.png
$assets.files.images.my-image.png
gives url of
<path-to-package>/images/my-image.png
as value (for light
field).
If an image with the same name but with -dark
suffix exists in the package,
i.e. <path-to-package>/images/my-image-dark.png
, then dark
field gets the
url of this file.
src
property and
ftd.image-src
type for more details.