ftd
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 FTD.
Type of a variable can be one of the built-in types, a record, or an or-type.-- 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 FTD 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 ftd, 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 $
.
ftd variables
are immutable
(can’t be changed once initialized).-- integer $x: 10 -- $x: 20
$processor$
: dynamic variablesftd
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 FTD 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.Have a question or need help?
Visit our GitHub Q&A discussion to get answers and subscribe to it to stay tuned.
Join our Discord channel and share your thoughts, suggestion, question etc.
Connect with our community!We welcome you to join our Discord community today.
We are trying to create the language for human beings and we do not believe it would be possible without your support. We would love to hear from you.