Basic syntax of a HammerScript expression
The syntax of the current HammerScript version is very simple and is solely based on
fetching values for variables or object attributes in different variable scopes. A
HammerScript expression always starts with a constructor for the variable scope to
operate on. After the constructor comes the variable or attribute to read the value from. The constructor creates an object from which a property is fetched. The properties are separated from the constructor by a period ".". Attributes can also be lists of variables. In that case list element names are also separated by a period from the attribute name.
{$ constructor.attribute }
{$ constructor.list_attribute.variable_name }
Elements of a HammerScript expression can be treated as objects or arrays as in JavaScript. If a variable name contains dots, the variable cannot be accessed as in the example above. These variables are accessed as arrays.
{$ constructor["attribute.with_dot"] }
{$ constructor.list_attribute["variable.name"] }
Object constructors
The syntax of the constructor depends on the sort of object to be fetched. Singleton
objects (classes with only one object instance) have a name that can be used directly.
Examples of singleton objects are http_get, var_global and system.
Example: Getting the value of a URL parameter.
{$ http_get.url_parameter_name }
Objects of classes with many instances need to be created using a unique identifier for the object. Examples of such classes are HammerKit_Component and HammerKit_File. The identifier is given to the constructor as an argument inside parentheses. The identifier is the database id attribute of an object. All object constructors and their possible identifiers in HammerScript are listed below.
Example: Getting the file name of a file with id 84.
{$ HammerKit_File(84).name }
Nesting HammerScript expressions
The value for the constructor argument can also come from a HammerScript expression.
Example: Getting the file name of a file with an id contained in the URL parameter "file_id". {$ HammerKit_File(http_get.file_id).name }
Nesting can also be used when the key of an array is available in a variable. For instance object variables can be fetched with dynamic key references by using nesting.
Example: Getting the file variable with the variable name contained in the URL parameter "variable_name" of a file with an id contained in the URL parameter "file_id" {$ HammerKit_File(http_get.file_id).variables[http_get.variable_name] }
User defined variables
Users can define own variables in the variable scopes var_global, var_private and
var_session. Variables are defined and given values in Set elements. Variable names can
consist of the characters _, a-z, A-Z and the ASCII characters with codes 127-255.