Func type templates
Custom functions (func type templates)
Custom func template can be used as functions. These templates only return the specified content and ignore the rest of the string content on them.
Note that func template do not have access to the usual .Data values in the template, anything that is to be used in there would need to be passed as arguments or loaded in the func with api calls.
Returning values
We specify the content we want to return with .Return in the func type templates.
For example (da-test-func):
This string will not be returned.
{{ .Return "this-will-be-returned" }}
And to call the func template we use it like this (da-test-page):
{{ .Tools.Func "da-test-func" }}
The output printed to the template here would be “this-will-be-returned”
Note that the function will return the first .Return value, anything that is after the first return will not be executed.
{{ .Return "this-will-be-returned" }}
{{ .Return "this-will-never-get-returned" }}
We can use regular template logic to pick the first value
{{ if $something }}
{{ .Return "will return if the condition is true" }}
{{ end }}
{{ .Return "if the condition is not true then it will return this instead" }}
Reading arguments
We can read arguments with the .Arg {index} command. Note that out of index arguments will always return an empty string.
To pass arguments to the functions we append the values to the func like with regular templates (da-test-page):
{{ .Tools.Func "da-test-func" "some-string" 2025 }}
To read the arguments in the func template (da-test-func):
<!-- Will get the value of "some-string" -->
{{ $argument1 := .Arg 0 }}
<!-- Will get the value of 2025 -->
{{ $argument2 := .Arg 1 }}
Api calls in functions
Func types have access to the app state functionality. This gives us better control over the api calls. Read about the functionality in the App state section.
Error
On extreme cases we can also make the function fail the entire flow. Calling this will display the goerp error page with the given error message.
Nothing after the error call will execute.
{{ .Error “my error message” }}