HASHSCRIPT v2
Updated: 17.11.2023 11:03The new version of HashJS
HS v2 is backwards compatible with v1.
Se documentation here:
https://tech.docly.net/Creating-forms/HASH-Templates
All examples will be updated soon with v2 syntax.
https://tech.docly.net/Creating-forms/HASH-Templates
All examples will be updated soon with v2 syntax.
Overview
What | How |
---|---|
Simplify the language syntax | • Switch to Javascript syntax in language • Still support for previous syntax • Show syntax errors when coding • Possible to declare your own functions (also so you can use and create your own libraries) • Better syntax highlighting when writing API functions (.HS extension) |
Improve error messages | • Provide line number of exceptions in compilation and runtime errors • Show 5 lines of code before and after with error highlighted |
As an extra measure we will implement a site validation feature to make sure your sites do not have errors.
* Prepare future support for - this will not be included initially for v2.
Changes and examples
For loops
Example - JS syntax:
<ul> #var index=1# #for(var item of List) {# <li>#index#. #item.Name#</li> #index++# #}# </ul>
The old syntax is still supported with brackets: [data-loop=items].
If statements
#if(a>b) {# <b>A is greater than B</b> #} else {# <b>B is equaler or greater than A</b> #}#
New features
Code blocks (curly brackets)
#{ // Comments in code var a=1; var b = 10; if(a>b) { var x = "123"; // do stuff return "test 1"; } else return "test 2"; }#
New server side .JS files (API folder only)
For better syntax highlighting, no need for #{ }#
var a = 1; var b = 10; if(a > b) { // ... return JSON(a); } else return JSON(b);
Only available for JSON functions that are placed in the #/API folder.
JS syntax for operators and variables
var a = 1; var b = 10; if (a + 5 > (5 - b) * 2) { a = a + 1; a++; a += b; }
Improved error messages
New error messages will not provide line number and 5 lines of code:
Error: [message here] Line 23: [line-2] Line 24: [line-1] Line 25: [line with error, code highlighted] Line 26: [line+1] Line 27: [line+2]
Declare functions
Example:
#{ function MyFunction(a,b) { return a * b; } }# Use function #MyFunction(3, 2)#
Multiples param 1 with param 2. Output will be 6.
Note that we are NOT CASE SENSITIVE on function names. Declaring the same function twice will simply overwrite the previous function code with no errors.
Note that we are NOT CASE SENSITIVE on function names. Declaring the same function twice will simply overwrite the previous function code with no errors.
Output:
Use function 6