|
|
Manual and Documentation
NOTE: This manual describes HammerKit version 3.5. To view documentation for the current release of HammerKit Studio, please go to http://manual.hammerkit.com/ |
|
|
|
|
|
|
|
|
|
|
|
|
/ / Syntax |
|
|
|
|
|
|
|
|
|
|
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 allways 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 cgi, session and var.
Example: getting the value of a URL parameter
{$ cgi.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 component, file and user. The identifier is given to the constructor as an argument inside brackets. Usually the identifier is the database id attribute of an object, but the attribute can be any attribute that is marked as unique for that object class.
Example: getting the file name of a file with id 84
{$ file(84).name }
Example: getting the full name of a user with username "username"
{$ user("username").fullname }
Constructor arguments of type string have to be quoted as the username in the above example. All object constructors and their identifiers in HammerScript are listed in the next section.
Nesting HammerScript expressions
The value for the constructor argument can also come from a HammerScript expression. In HammerScript v0.9 only two levels of constructor nesting is supported.
Example: getting the file name of a file with an id contained in the URL parameter "file_id"
{$ file(cgi.file_id).name }
Nesting can also be used when the key of an array is 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"
{$ file(cgi.file_id).variables[cgi.variable_name] }
User defined variables
Users can define own variables in the variable scopes cgi and var. Variables are defined and given values in the Logic module. Variable names can consist of the characters _, a-z, A-Z and the ASCII charachers with codes 127-255. |
� HammerKit Oy 2008 |
UPDATED: 19.04.2008 11:32 |
|