Understanding of function variable #9
-
Hi, When I look at the code, it seems that we can add a "function variable" into a template like Then in my json, I can add the variable and then all the string Is there another feature associated to these "function variables" or it is just the way to have variables with a more flexible variable name (which is useful for me) ? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
TL;DR Function variables are text variables. They are useful if you want to allow usage of programming-like syntax in order to add multiple variables interpretations possibilities. But, Lotemplate doesn't interpret them in a different way. Note that this answer only speaks about text variables, but the same exact text can be used to speak about table variables (as they also support this syntax) What are Function Variables?Function variables are just regular text variables, and operate in the same way as text variables - in terms of code and usage. The only thing that really differentiates them from regular text variables is their syntax.
As they are text variables, lotemplate will return them just like regular variables: {
"my_func($my_var)": {
"type": "text",
"value": ""
}
} The pattern to match them is very specific and follows a specific syntax: \$\w+(?:\((?<arg>(?R)|"[^"]*"|[^$"\s()][^\s()]*)(?:[+ ](?&arg))*\))? Examples include:
Why use Function Variables?Here's an example: Suppose you are developing software to fill documents containing variables such as You can simply instruct users to write How to Use Function Variables?As previously mentioned, function variables are just text variables, so lotemplate does not treat them any differently. You have to parse the variable names returned by lotemplate yourself and correctly set the variable value relative to the variable name - all on your own. As previously mentioned, lotemplate does NOT provide any logic related to function variables - only the search for this type of pattern. Why not treat function variables as a type in their own right / Why not treat function variables as entiere variables / Why not return them parsed?Of course, the ideal scenario would be for lotemplate to return variables like this: {
"my_func": {
"type": "function",
"value": ""
},
"my_var": {
"type": "text",
"value": ""
}
} For a text like this: However, this would require code to be sent and executed by Lotemplate. Because you cannot give the return value, you have to describe what your function is actually doing. This poses 3 issues:
Instead, by treating function variables as regular text variables, lotemplate provides a flexible way to allow for custom variable interpretation while still maintaining security and simplicity. It's up to the user to parse and interpret the variables returned by lotemplate in a way that fits their needs. In summary, function variables are a powerful tool for allowing custom interpretation of variables in lotemplate, but they should be treated as regular text variables and parsed by the user to avoid security and complexity issues. |
Beta Was this translation helpful? Give feedback.
TL;DR Function variables are text variables. They are useful if you want to allow usage of programming-like syntax in order to add multiple variables interpretations possibilities. But, Lotemplate doesn't interpret them in a different way.
Note that this answer only speaks about text variables, but the same exact text can be used to speak about table variables (as they also support this syntax)
What are Function Variables?
Function variables are just regular text variables, and operate in the same way as text variables - in terms of code and usage. The only thing that really differentiates them from regular text variables is their syntax.
$my_var
- regular variable$my_func($my_var)
- f…