HASH Templates
HS (hashscript) templates are used to process and bind data values to text documents and generate output such as HTML or JSON.
© 2010 - 2022 DOPS AS | www.dops.no
Updated: 07.11.2022 19:07
© 2010 - 2022 DOPS AS | www.dops.no
About hash templates
Hash templates creates document templates. With the use of hash templates you can customize how templates in your solution works.
By using #fieldname# in your text, you can merge values from objects into your text.
The abbreviation for Hash templates is HTML#
By using #fieldname# in your text, you can merge values from objects into your text.
The abbreviation for Hash templates is HTML#
Hash templates are used for serverside databinding and simple related logic and calculations.
Statements
Statements are embedded within HTML or other simmillare text markup. Each statement starts with and ends with a # character.
Example with single statements:
Name: #Name#<br> Position: #Position#<br>
This reads out the data property name and position into the markup. Single statements can NOT have spaces or line breaks inside.
Use brackets for multiple statements:
#{[Name];[Position]}# Name: #Name#<br> Position: #Position#<br> #{[/Name];[/Position]}#
The example above only prints out name and position if BOTH have values. Brackets CAN have spaces and line breaks inside.
Formatting fields
Date fields
Formatted date: #Date."dd.MM.yy"#
Parameters (NB! Case sensitive!):
Format specifier | Description | Examples |
---|---|---|
"d" | The day of the month, from 1 through 31. | 2009-06-01T13:45:30 -> 1 2009-06-15T13:45:30 -> 15 |
"dd" | The day of the month, from 01 through 31. | 2009-06-01T13:45:30 -> 01 2009-06-15T13:45:30 -> 15 |
"ddd" | The abbreviated name of the day of the week. | 2009-06-15T13:45:30 -> Mon (en-US) 2009-06-15T13:45:30 -> Пн (ru-RU) 2009-06-15T13:45:30 -> lun. (fr-FR) |
"dddd" | The full name of the day of the week. | 2009-06-15T13:45:30 -> Monday (en-US) 2009-06-15T13:45:30 -> понедельник (ru-RU) 2009-06-15T13:45:30 -> lundi (fr-FR) |
"h" | The hour, using a 12-hour clock from 1 to 12. | 2009-06-15T01:45:30 -> 1 2009-06-15T13:45:30 -> 1 |
"hh" | The hour, using a 12-hour clock from 01 to 12. | 2009-06-15T01:45:30 -> 01 2009-06-15T13:45:30 -> 01 |
"H" | The hour, using a 24-hour clock from 0 to 23. | 2009-06-15T01:45:30 -> 1 2009-06-15T13:45:30 -> 13 |
"HH" | The hour, using a 24-hour clock from 00 to 23. | 2009-06-15T01:45:30 -> 01 2009-06-15T13:45:30 -> 13 |
"m" | The minute, from 0 through 59. | 2009-06-15T01:09:30 -> 9 2009-06-15T13:29:30 -> 29 |
"mm" | The minute, from 00 through 59. | 2009-06-15T01:09:30 -> 09 2009-06-15T01:45:30 -> 45 |
"M" | The month, from 1 through 12. | 2009-06-15T13:45:30 -> 6 |
"MM" | The month, from 01 through 12. | 2009-06-15T13:45:30 -> 06 |
"MMM" | The abbreviated name of the month. | 2009-06-15T13:45:30 -> Jun (en-US) 2009-06-15T13:45:30 -> juin (fr-FR) 2009-06-15T13:45:30 -> Jun (zu-ZA) |
"MMMM" | The full name of the month. | 2009-06-15T13:45:30 -> June (en-US) 2009-06-15T13:45:30 -> juni (da-DK) 2009-06-15T13:45:30 -> uJuni (zu-ZA) |
"s" | The second, from 0 through 59. | 2009-06-15T13:45:09 -> 9 |
"ss" | The second, from 00 through 59. | 2009-06-15T13:45:09 -> 09 |
"y" | The year, from 0 to 99. | 0001-01-01T00:00:00 -> 1 0900-01-01T00:00:00 -> 0 1900-01-01T00:00:00 -> 0 2009-06-15T13:45:30 -> 9 2019-06-15T13:45:30 -> 19 |
"yy" | The year, from 00 to 99. | 0001-01-01T00:00:00 -> 01 0900-01-01T00:00:00 -> 00 1900-01-01T00:00:00 -> 00 2019-06-15T13:45:30 -> 19 |
"yyy" | The year, with a minimum of three digits. | 0001-01-01T00:00:00 -> 001 0900-01-01T00:00:00 -> 900 1900-01-01T00:00:00 -> 1900 2009-06-15T13:45:30 -> 2009 |
"yyyy" | The year as a four-digit number. | 0001-01-01T00:00:00 -> 0001 0900-01-01T00:00:00 -> 0900 1900-01-01T00:00:00 -> 1900 2009-06-15T13:45:30 -> 2009 |
"yyyyy" | The year as a five-digit number. | 0001-01-01T00:00:00 -> 00001 2009-06-15T13:45:30 -> 02009 |
"tt" | The AM/PM designator. | 2009-06-15T13:45:30 -> PM (en-US) |
\ | The escape character. | |
Any other character | The character is copied to the result string unchanged. | 2009-06-15T01:45:30 (arr hh:mm t) -> arr 01:45 A |
Number fields
Formatted number: #tall."N"# Same number as above, in different format: #tall."0.000"#
Parameters (NB! Case sensitive!):
If you want to add additional symbols before or after the integer and the decimal you can use the \ character before quoting the symbol you want to merge in .
Examples are:
Examples are:
Format | Description | Examples |
---|---|---|
#feltnavn."0\,\-"# | To display numbers as typical prices without decimals | 100,- |
#feltnavn."\k\r\. 0.00"# | Will display numbers with 2 decimals and kr. front. | kr. 100,50 |
#feltnavn."##,######"# | Thousands separator | 1,054.32 |
#feltnavn."##,######\,\-"# | Thousands separator with trailing ,- | 1,054.32,- |
Setting culture
By setting / changing culture the format functions will use the specified culture for formatting.
#setculture("no")# or #setculture(1044)#
Apply with function
You can also use the function Format(value,string). See "Array / string functions" chapter.
Example:
#format(datevalue,"dd.MM.yyyy")#
Formatting and encoding of text
Examples:
- Url-encoding: #displayurl#?p=#param.urlencode#
- Html-encoding: #displayurl.htmlencode#
- Attributt-encoding: <a href="#displayurl.attribencode#">....</a>
Url-encoding: Used if special characters is to be encoded from text into a URL parameter.
Html-encoding: Used if symbols that can be interpreted by the browser as HTML tags is to be displayed in web content.
Attributt-encoding: Used if text values with symbols should be entered in attributes such as url for links to pages or files.
Document properties
Field | Type | Description |
---|---|---|
Filename | string | Docly™ filename for document |
Folder | object | Folder object for document. Exposing its properties. |
Version | string | Last modified timestamp formatted as: "yyMMddHHmm" |
Created | datetime | Creation timestamp for document |
CreatedBy | string | Email of user who created the document |
LastWriteTime | datetime | Last modified timestamp for document |
LastWriteBy | string | Email of user who modified the document last |
User | string | Email of user generating document |
May be read and merged in to the document as any fields, ie:
<div> Filename: #Filename#<br /> Folder: #Folder.Name#<br /> Version: #Version#<br /> </div>
If statements and conditions
Example:
#[image]# <img src="#image#" alt="#alttitle#" /> #[/image]#
To check that the field does not exist or has value use the ! operator before the criterion:
#[!image]# Har ikke bilde #[/!image]#
The example shows a condition definition with content. The condition says that the image must have a value, and inside the condition area is the text to be added if the condition is satisfied. The "<img ... />" tag will be entered in the result if the "image" field has a value.
#[type="test"]# <img src="#image#" alt="#alttitle#" /> #[/type="test"]#
ATTENTION! < Must be written as & lt; in html code. If you edit directly in WYSIWYG editor, type <
#[type<"test"]# <img src="#image#" alt="#alttitle#" /> #[/type<"test"]#
You can also use ' instead of " in value indication.
This is eg. useful inside html attributes where " creates invalid html.
ATTENTION! TinyMCE can create some problems if it do replace ' with &# character code.
This is eg. useful inside html attributes where " creates invalid html.
ATTENTION! TinyMCE can create some problems if it do replace ' with &# character code.
<div style="#[type<'test']#display:none#[/type<'test']#"> Tekstinnhold eller annet </div>
The symbol > must be written as > html code but not in WYSIWYG
#[type>annetfelt]# <img src="#image#" alt="#alttitle#" /> #[/type>annetfelt]#
The examples show syntax for checking with operators. Valid operators:
Operator | Description |
---|---|
<> | Not equal |
!= | Not equal (same as previous) |
== | Equals |
> | More than |
< | Less than |
>= | More than or equal to (=> also allowed) |
<= | Less than or equal to (=< also allowed) |
~= | value contains the text - not case sensitive |
^= | value contains the text - case sensitiv |
~! | value does not contain the text - ikke case sensitiv |
^! | value does not contain the text - case sensitiv |
$= | Ends with string - not case sensitive |
$! | Not ends with string - not case sensitive |
=$ | Starts with string - not case sensitive |
!$ | Not starts with string - not case sensitive |
ATTENTION! Always remember " or ' around constant values in conditions! Also for numbers!
Looping arrays
Looping of arrays can be done by using the data-loop command, ie:
<ul> #[data-loop="array"]# <li>#Title#</li> #[/data-loop="array"]# <ul>
It is also possible to use the data-loop attribute but not recommended as it may be slower and not supported in the future:
<div data-loop="children"><div>.......</div></div>
_list_index - Provides item number (zero indexed). The example showing title for the first 10 elements only:
[_list_index."000"<"010"]<div>Element: #title#</div>[/_list_index."000"<"010"]
Worth noting here is that there is a string compare used. "000" converts numbers to always have 3 digits. Comparing numbers is not supported, only string!
Lines of text in text fields
Memo text fields can be looped, each line will be an element. See the example below:
#[data-loop="memofelt"]# <div>#text#</div> #[/data-loop="memofelt"]#
Loop in loop
It is possible to have loops running inside other overarching loops. See the example below:
#[data-loop="users"]# <div>Bruker med navn: #name#</div> <!-- Brukernavn --> <div>Har redigeringstilgang til følgende mapper:</div> <ul> #[data-loop="editor"]# <li>#name#</li> <!-- Mappenavn --> #[/data-loop="editor"]# </ul> #[/data-loop="users"]#
Recursive loop
Recursive / nested loops use the {{current}} keyword in the template, see example:
#[data-loop="Elements"]# <h2>#Title#</h2> <span>#Content#</span> <blockquote>#[data-loop="Elements]#{{current}}#[/data-loop="Elements]#</blockquote> #[/data-loop="Elements"]#
Specify multiple loops with same template
Use the {templatename} notation, example:
// Loop array Items: #[data-loop="Items"]# Title: #Title#<br /> #[/data-loop="Items"]# // Loop another array and reuse the template: #[data-loop="Items2"]#{Items}#[/data-loop="Items2"]#
Array commands
Sum(array,field)
Sums fields from an array, returns a double.
Parameter | Type | Description |
---|---|---|
array | Array of object | IEnumerable of objects |
field | String | Name of numeric property or field to sum on array. |
Sum(Detaljer,"Antall")
MULTIPLE LEVEL SUMS
Note that recursive Sum(Detaljer,Sum(SubArray,"Field")) does not work!
Use: Sum(Select(Detaljer,SubArray),"Field")
Note that recursive Sum(Detaljer,Sum(SubArray,"Field")) does not work!
Use: Sum(Select(Detaljer,SubArray),"Field")
Select(array,field)
Select a single field from an object array, returns an array.
Parameter | Type | Description |
---|---|---|
array | Array of object | IEnumerable of objects to iterate |
field | String | Name of field to select out of specified array |
Select(Detaljer,"Antall")
COUNTING NESTED OBJECTS
See examples below:
See examples below:
#setvar("allact",ActorList)# #setvar("allobj",Select(ObjectChapters,"Objects"))# #setvar("allscr",Select(ScreenChapters,"Screens"))# #setvar("allfunc",Select(Select(ScreenChapters,"Screens"),"Functions"))# Count in ActorList array: #allact.Length# Count all Objects: #allobj.Length# Count all screens: #allscr.Length# Count all functions: #allfunc.Length#
Where(array,criteria)
Selects entire objects from an array based on specified criteria.
Parameter | Type | Description |
---|---|---|
array | Array of object | IEnumerable of objects to iterate |
criteria | String | Criteria for each object used to filter objects from array |
Where(Items,"Field>0")
First(array,criteria)
Selects entire objects from an array based on specified criteria.
Parameter | Type | Description |
---|---|---|
array | Array of object | IEnumerable of objects to iterate |
criteria | String | Criteria for each object used to filter objects from array |
First(Items,"Id='123'")
MULTIPLE LEVEL LOOKUP
Use: First(Select(Items,"SubItems"),"Id='123'")
Use: First(Select(Items,"SubItems"),"Id='123'")
Any(array,criteria)
Checks if any item in the array meets criteria and returns true or false based on this.
Parameter | Type | Description |
---|---|---|
array | Array of object | IEnumerable of objects to iterate |
criteria | String | Criteria to test objects in specified array. If any are true then function returns true, if all are false then it returns false. |
Any(Items,"Field>0")
Avg(array,field)
Gets the average double value from an array. Returns a double.
Parameter | Type | Description |
---|---|---|
array | Array of object | IEnumerable of objects to iterate |
field | String | Name of numeric property or field to create average for specified array. |
Avg(Detaljer,"Antall")
Skip(array,count)
Same as .NET skip. Returns a new array where the specified count of items has been removed from the start of the array.
Example skips the 6 first items in the array and loops the rest:
Example skips the 6 first items in the array and loops the rest:
<div data-loop="Skip(array,6)">....</div>
Sort(array,field,[convert])
Returns specified array sorted in ascending order by specified field.
<div data-loop="Sort(array,'Date')">....</div>
To convert (optional parameter) values to numbers or dates use the following syntax:
<div data-loop="Sort(array,'Date','CInt')">....</div> OR <div data-loop="Sort(array,'Date','CDate')">....</div>
You can also use any other function as the convert parameter. Such as cdbl, getvar, round, floor, ceilling, md5, htmldecode/encode, urldecode/encode.
SortDesc(array,field,[convert])
Returns specified array sorted in descending order by specified field.
<div data-loop="SortDesc(array,'Date')">....</div>
See "Sort" documentation for example of [convert] optional parameter.
Take(array,count)
Same as .NET take. Returns a new array with the specified count of items taken from the start of the array.
Example loops the 5 first items from the array:
Example loops the 5 first items from the array:
<div data-loop="Take(array,5)">....</div>
Concat(array,array,[array],...)
Same as .NET concat. Concats multiple arrays to one.
Example loops an array that merges 3 arrays to one:
Example loops an array that merges 3 arrays to one:
<div data-loop="Concat(array1,array2,array3)">....</div>
Union(array,array,[array],...)
Same as .NET union. Merges multiple arrays to one, but removes duplicate items.
Example loops an array that merges 3 arrays to one:
Example loops an array that merges 3 arrays to one:
<div data-loop="Union(array1,array2,array3)">....</div>
Functions
Hash templates may also be extended with extra functions at programming level (function injection).
Built in functions are:
Built in functions are:
Attachments
Function | Description |
---|---|
AttachFile64(filename) | Returns specified file as a base64 encoded string. |
LinkFile(fileid) | Gets official URL for specified file. |
LinkFile(fileid,filename) | Gets official URL for specified file and starts a download with specified filename. |
LinkImage(filename,width,height,mode) | Gets official URL for specified image, with scaling as specified. |
Scaling modes explained
Scale to fit (0)
Systemet skalerer ned bildet slik at de passer innenfor formatet som er definert i websidene.
- Enten er bredden og/eller høyden definert
- Bildet fyller ikke hele målområdet dersom høyde/bredde formatet i bildet ikke stemmer
- Bildet blir aldri skalert opp dersom det er for lite
- Gjennomsiktig bakgrunn virker ikke dersom bildet omskaleres
- Bilder får optimal filstørrelse
Examples:
Scale to fill (1)
Systemet tar automatisk utsnitt av bildet for å passe formatet som er definert i websidene.
- Alle bilder blir like store, og nøyaktig samme størrelse som definert uansett høyde/bredde forhold
- Hele bildet kommer ikke alltid med
- Utsnitt kan bli gjort, topp/bunn eller venstre/høyre del kan bli kuttet vekk fra bildet.
- Gjennomsiktig bakgrunn virker ikke dersom bildet omskaleres
- Bilder kan bli skalert opp dersom de er for små
- Bilder får optimal filstørrelse
Examples:
No ratio rescale (2)
Image is rescaled and stretched.
Scale with white margin (3)
Systemet skalerer ned bildet slik at de passer innenfor formatet som er definert i websidene og fyller området rundt med hvit farge slik at bildet alltid får målstørrelsen.
- Bildet fyller hele målområdet selv om høyde/bredde formatet i bildet ikke stemmer
- Bildet blir ikke skalert opp dersom det er for lite
- Gjennomsiktig bakgrunn virker ikke dersom bildet omskaleres
- Bilder får optimal filstørrelse
- Bildet kan bli fylt ut med hvite kanter over eller under dersom størrelsesformatet ikke matcher målområdet
Examples:
Scale with black margin (4)
Tilsvarende forrige men med svarte marger.
Examples:
No scaling (5)
Bilder brukes i samme størrelse som de er lastet opp og blir ikke omskalert.
- Bildedata blir aldri forandret
- Nettleseren skalerer evt. bildene selv dersom det defineres i CSS
- Bilder kan bli unødvendig store i forhold til visningsstørrelse
Array / string functions
Function | Description |
---|---|
GetFirst(array) | Returns first item in an array |
GetLast(array) | Returns last item in an array |
GetIndex(array, integer) | Gets item by index from an array |
Join(string[]) | Joins strings. No seperator can be specified. |
Join(seperator,lastsep,string[]) | Joins strings with custom seperators. Last seperator is used between the last words. Example: Join(", "," and ",stringarray) (Joins an array with commas and then "and") |
Replace(string text, string find, string replaceWith) | Replaces text within string. Params are: valuestring, findstring, replacewithstring. |
Trim(string text, string[] trimchars) | Trims all trim chars from edges of text. Specify chars or multiple strings. |
Substring(string text, int start, optional int length) | Extracts specified part from a string. Start is zero indexed. |
Split(string text) | Splits lines in a string into string array. Removes empty lines. |
Split(string text, string seperator) | Splits a string into string array. |
Chr(integer()) | Returns characters by ASCII numbers. |
LCase(string text) | Turns specified string(s) to lower case. |
UCase(string text) | Turns specified string(s) to upper case. |
CreateArray(type) | Creates a new array of specified type. Valid types are "string", "integer" or "object". |
Push(array, item) | Adds an item to the end of an array. |
Pop(array) | Removes first item in array. |
InsertAt(array, index, item) | Inserts an item at a specified index. |
Distinct(array) | Returns all unique items in array. |
RemoveEmptyLines(string) | Removes empty lines (empty or white space). |
UCamel(string) | Removes spaces from a string and camel cases the letters accordingly. Forces first letter to upper case. Replaces æøå. |
LCamel(string) | Removes spaces from a string and camel cases the letters accordingly. Forces first letter to lower case. Replaces æøå. |
FormatHTML(string) | Parses HTML and returns it in an indented format. |
JSON(object) | Converts any object to JSON string. |
UNSJON(string) | Converts any JSON string to an object. |
SetCulture(culturestring) | Sets culture for default comma chars date formatting etc. |
Format(value,string) | Applys formatter (number or date) on a value. |
CreateArray function example:
#{ setvar("x",createarray("string")); setvar("x",push(x,"x")); setvar("x",push(x,"x")); setvar("x",push(x,"y")); setvar("x",push(x,"z")); }# <ul data-loop="distinct(x)"> <li>#this#</li> </ul>
Encoding
Function | Description |
---|---|
StripHtml(string) | Removes all html from string and leaves document content |
StripTags(string) | Removes all html or xml tags from string |
HtmlEncode(string) | Encode any HTML characters so they are displayed in the page as symbols. |
UrlEncode(string) | Encodes a string for use as URL parameters |
HtmlAttributeEncode(string) | Encodes a value for use in an attribute |
HtmlDecode(string) | Decodes HTML encoded string |
UrlDecode(string) | Decodes Url encoded string |
UrlPathEncode(string) | Encode string for use in urlpath |
TextToHtml(string) | Combination of: - Changes line breaks to <br /> tags. - Auto hyphens on 24 chars. - Adds links to all links in text |
AutoLinkText(string) | Automatically inserts HTML a tag on links in text. |
Hyphen(string) | Adds hyphens to text. |
Math functions
Function | Description |
---|---|
Mul(double[]) | Multiplies specified numbers |
Add(double[]) | Adds specified numbers and returns the sum |
Sub(double[]) | Subtracts specified numbers in same order |
Div(double[]) | Divides specified numbers in same order |
Cint(object) | Converts specified object to integer |
CStr(object) | Converts specified object to string, if many objects they are joined to one string. |
GetDate() | Returns DateTime object with current time. |
Mod(double a, double b) | Modulus (%) operator. result = a % b (c#) or a MOD b (vb). |
Floor(double a) | The largest integer less than or equal to a |
Round(double a) | Rounds a value to the nearest integer |
Ceiling(double a) | Returns the smallest integer greater than or equal to the specified number |
Cdbl(object) | Converts specified object to integer |
Cdate(object,format) | Converts string to datetime value. Format default if not specified: "yyyy-MM-dd". (Uses the .NET DateTime.ParseExact() function with Invariant culture.) |
DateDiff(from, to) | Params "from" and "to" must both DateTime. Returns timespan / distance between date1 and date2. (Meaning in C# return date2 - date1) |
Embedding
Function | Description |
---|---|
DownloadFromUrl(url) | Downloads a file from specified url. |
DownloadFromUrl64(type, url) | Downloads a binary file from specified url and generates "data:###;base64,#####" embed string. Example: DownloadFromUrl64("image/png", "http://www.ikx.no/logo.gif") |
Include
Includes another template within this template. (Watch out for stack overflow!)
#include("Othertemplate.html")#
Make sub parts of your template in other templates and combine them together in different ways.
Or include from a file's internal defined templates:
#include("My document","Article.html")#
NULLC - Null-coalescing
This is the null-coalescing operator. It returns the left-hand operand if the operand is not null; otherwise it returns the right hand operand.
Example:
#nullc(field1,field2,field3,field4)#
The example above will return the first variable that is not null. If field1 to 3 are null it will return field4. If field4 is null it will return an empty string.
Redirect function
redirect(url)
- url - url to redirect user to (301 http code)
#redirect("http://www.google.com")#
User is in this example redirected to Google's page.
Chapter functions
Use the chapter functions to easily keep track of counter for chapters / nested chapters in your HASH code.
Function | Description |
---|---|
chinit(name) | Init a counter in a variable with given name. |
chstep(name) | Step forward on counter with specified name. |
chdestep(name) | Step backward on counter with specified name. |
chpush(name) | Step inwards (add a new level to counter). |
chpop(name) | Step upwards (remove a level from counter). |
Example:
No example is available at the moment.
Variable functions
Read and set variables.
Function | Description |
---|---|
SetVar(name,value) | Creates or updates a variable with the specified value. |
Get(name) | Gets a variable, only needed for variables with space or special chars in the name. |
SetProp(name) | Resets or inits an object to specified variable name. |
SetProp(name,prop,value) | Sets a property on the specified variable name. The variable will be automatically initated. |