Websydian v6.1 online documentationOnline documentation - WebsydianExpress v3.5

Meta template script markers

Special Markup

The meta templates support a wide range of special script markers. Script markers are replacement markers that will perform some kind of functionality in order to obtain the value to be inserted into the final template that the meta template will generate.

This document describes each of these script markers in detail.

In the format descriptions below cursive text indicates a part of the replacement marker that will be different for each usage of the replacement marker.

Note that the script markers described in this document is only supported in the meta templates.

Retrieving values from the XML document

The following script markers are used to retrieve information from the XML document provided to the template generator and used by the meta templates to generate the final templates.

%GETVALUE - Retrieve a value specified by an XPath expression

Format: /(%GETVALUE-XPathExpression)

XPathExpression can be either an absolute or a relative expression.

When a relative XPathExpression is specified, the current meta template determines what the current element is.

If the node specified by the XPathExpression is an attribute node, the marker will be replaced by the attribute value.

If the node specified by the XPathExpression is an element node, the marker will be replaced with the text content of the element node.

If the node specified by the XPathExpression is of another type - or the XPath expression doesn't correspond to a node in the document - the marker will just be removed.

Note that XPath expressions containing function-calls - for example: concat(node,node) - can't be specified in the replacement marker, as there is no way for the runtime to know that the last parenthesis of the function call isn't the end of the replacement marker.

Samples

The meta template FIELD_output_wsydatefield.JS in the folder FIELD_DEFINITIONS is used to define date fields as output fields in the detail region.

This meta template handles a specific Field element in the XML document. This contains the line:

Ext.apply(/(PAGEIMPL).wsyOutputFields./(%GETVALUE-@plex_impl), /(%GETVALUE-./SourceCodes/SourceCode[@plex_name="wsydetailproperties"]/literal));

This line shows two examples of the %GETVALUE script marker.

The first simply finds the attribute @plex_impl for the current field element and replaces it with the retrieved value - so for the Field element shown below, the marker will be replaced with AAb1A

The second marker contains a somewhat more complex XPath expression, that in this case will be replaced with the text { minValue: new Date(), format: 'Y-m-d' } when applied to the Field element shown below:

So the resulting line in the generated template would be:

Ext.apply(/(PAGEIMPL).wsyOutputFields.AAb1A, { minValue: new Date(), format: 'Y-m-d' });

%@ - Retrieve an attribute value for the current element

Format: /(%@AttributeName)

This is a shorthand notation for /(%GETVALUE-@AttributeName).

It retrieves the value of the attribute specified by AttributeName in the current element.

If the current element doesn't contain this attribute, the marker will just be removed.

Samples

In the line above, the script marker /(%GETVALUE-@plex_impl) could have been replaced with the shorthand notation: /(%@plex_impl).

Including another meta template

%INCLUDE - Include another meta template

Format: /(%INCLUDE-METATEMPLATE?suffix=---&templatefolder=...)

METATEMPLATE (Mandatory)

The name of the meta template to be included.

Suffix (Optional)

Defaults to blank if no suffix is added.

The suffix specifies a suffix for the meta template name.

This enables you to refer multiple instances of the same meta template.

The filename of the meta template will be: PAGENAME_suffix.extension - the file extension is determined by the file extension of the MAIN meta template currently being handled (e.g. htm, js, and json).

The suffix in the INCLUDE marker can have three possible formats:

  1. suffix=constant
    where constant represents a string value. This value will be appended together with a _ (underscore) to the meta template name.
  2. suffix=/[FieldName]
    The suffix will be determined by a value in WsyDetails/WsyGrid.
  3. suffix=/[@AttributeName]
    The suffix will be determined by an attribute value from the current element in the XML document,
Templatefolder (Optional)

Defaults to the base meta template folder (as specified in the Websydian.prop/Websydian.ini file)

The template folder specifies a folder under the base meta template folder. This will be used to locate the specific instance of the meta template you would like to include.

The format of the template folder is:

templatefolder=foldername

templatefolder=path/foldername

The template folder specified is to be specified as a relative folder to the base meta template folder. 

The parameter may not have either / or \ as the first or last character.

Any INCLUDE markers not specifying a templatefolder will revert to root meta template location. That is the templatefolder will not affected any subsequent INCLUDE script markers.

Samples

All the meta templates referred below can be found scoped by subfolders of the meta templates folder delivered as part of the Websydian installation.

1. An include script marker with a templatefolder and no suffix

The MAIN.HTM meta template in the wsystandardpage folder contains the %INCLUDE marker:

/(%INCLUDE-CHILDPAGES?templatefolder=WSY_GENERAL_DEFINITIONS)

This instructs the MAIN meta template to include the CHILDPAGES meta template - and that it should use the meta template CHILDPAGES.HTM in the WSY_GENERAL_DEFINITIONS folder.

Note that the file extension .HTM always will be the same as for the meta template the %INCLUDE marker is placed in

2. An include script marker with a templatefolder and a suffix

This %INCLUDE script marker is also found in the MAIN.HTM meta template in the wsystandardpage folder:

/(%INCLUDE-CHILDPAGES?suffix=create&templatefolder=WSY_GENERAL_DEFINITIONS)

Again, MAIN meta tempalte is instructed to include the CHILDPAGES meta template - but this time it should use the meta template CHILDPAGES_create.HTM in the WSY_GENERAL_DEFINITIONS folder.

3. An advanced include script marker

A more advanced example of an include statement can be found in the meta template DETAILFIELDS_output.JS in the folder WSY_GENERAL_DEFINITIONS:

/(%INCLUDE-FIELD?suffix=output_/[@wsyfieldtype]&templatefolder=WSY_FIELD_DEFINITIONS)

This instructs the meta template DETAILFIELDS_output.JS to include the meta template FIELD_output_ and then appending the value of the attribute wsyfieldtype of the Field element from the XML document.

The included meta template after resolving the attribute value of wsyfieldtype could be FIELD_output_wsydatefield.JS.

Edit point markers

These markers support the creation of edit points in the generated templates. In short edit points are areas in the final template where you can add custom code that will be retained event though running the template generation again and again.

%EDITPOINTJS - Insert an edit point marker in a JS section

Format: /(%EDITPOINTJS - EditPointName)

Generates the required mark up in the final template for creating an edit point in the java script area of the file.

Samples

In the meta template MAIN.HTM in the wsystandardpage folder you can find the following edit point marker:

/(%EDITPOINTJS-wsyAfterChildPages)

When generating the final templates the first time this will generate the following in the generated template:

// !wsyd.editpoint.begin - wsyAfterChildPages
// !wsyd.editpoint.end - wsyAfterChildPages

Note that even though the meta template - and therefore the generated template are .HTM templates, JS edit points can still be inserted if the edit point is placed inside <script>...</script> markers.

When the template generation is run again for the PageGenerator, any content placed between the two comments will be extracted - and when the %EDITPOINTJS marker is reached, the comment markers and the content placed between them will be entered into the generated template

%EDITPOINTHTM - Insert an edit point marker in an HTML section

Format: /(%EDITPOINTHTM - EditPointName)

Generates the required mark up in the final template for creating an edit point in the htm area of the file.

Samples

In the meta template MAIN.HTM in the wsystandardpage folder you can find the following edit point marker:

/(%EDITPOINTHTM-wsyAfterChildPagesInformation)

When generating the final templates the first time this will generate the following in the generated template:

<!-- !wsyd.editpoint.begin - wsyAfterChildPagesInformation -->
<!-- !wsyd.editpoint.end - wsyAfterChildPagesInformation -->

When the template generation is run again for the PageGenerator, any content placed between the two comments will be extracted - and when the %EDITPOINTHTM marker is reached, the comment markers and the content placed between them will be entered into the generated template

Generated section markers

These markers support the creation of generated section markers in the generated templates. In short the generated section markers enables you to "freeze" an area in the final template that the template generator will not replace or overwrite.

%GENSECTIONHTMBEGIN - Insert a begin GENSECTION marker in an HTML section

Format: /(%GENSECTIONHTMBEGIN - GenSectionName)

Generates the required markup for the generated section start marker to be placed in the html section of the final template.

%GENSECTIONHTMEND - Insert an end GENSECTION marker in an HTML section

Format: /(%GENSECTIONHTMEND - GenSectionName)

Generates the required markup for the generated section end marker to be placed in the html section of the final template.

%GENSECTIONJSBEGIN - Insert a begin GENSECTION marker in a JavaScript section

Format: /(%GENSECTIONJSBEGIN - GenSectionName)

Generates the required markup for the generated section start marker to be placed in the java script section of the final template.

%GENSECTIONJSEND - Insert an end GENSECTION marker in a JavaScript section

Format: /(%GENSECTIONJSEND - GenSectionName)

Generates the required markup for the generated section end marker to be placed in the javascript section of the final template.

Other special script markers

%SLASH - insert a /

Format: /(%SLASH)

This marker is replaced by a forward slash "/". This is used to build replacement markers in the generated template.

Samples

The MAIN.json.js template in the wsystandardpage folder contains the following block that contains two %SLASH markers

/(%SLASH)(%IFNEQ-WSPARINC=*Yes)
{    success: true
    ,wsyResponse: function() {}

}
/(%SLASH)(%ENDIF)

In the generated template, this will result in:

/(%IFNEQ-WSPARINC=*Yes)
{    success: true
    ,wsyResponse: function() {}

}
/(%ENDIF)

In this way, it is possible to build the %IFNEQ and %ENDIF script markers.

%CURRENTDATETIME - insert a timestamp

Format: /(%CURRENTDATETIME)

Inserts a timestamp specifying the current time in the generated template. This makes it possible to check when the final templates have been generated - without having to rely on the modified date of the file.

%SET

Format: /(%SET-name=value)

The SET marker writes a name/value pair to memory. You can check the value in a child page using the /(%IFEQ-$name=CompareValue) statement.

Samples

The MAIN.js meta template in the wsystandardpage folder contains the following block:

,baseParams: { /(%SET-firstItem=true)
    /(%INCLUDE-DETAILFIELDS?suffix=formfields_hidden&templatefolder=WSY_GENERAL_DEFINITIONS)
}

This sets the current value of the memory variable named "firstItem" to "true".

In the meta template that will be used based on the INCLUDE statement: DETAILFIELDS_formfields_hidden.JS in the WSY_GENERAL_DEFINITIONS folder, you can find the following code:

<!--/(Grid)-->
    /(%IFEQ-@plex_roleinpage=input)
        /(%IFEQ-@plex_hidden=true)
            /(%IFEQ-$firstItem=false),/(%ENDIF)
            /(%IFEQ-$firstItem=true)/(%SET-firstItem=false)/(%ENDIF)
            /(%GETVALUE-@plex_impl): /(PAGEIMPL).fieldvalues./(%GETVALUE-@plex_impl).literal
        /(%ENDIF)
    /(%ENDIF)
<!--/(Grid)-->

The fact that the code is placed inside the /(Grid) markers means that this will be done several times - in this case once for each hidden field of a form. The aim of the code is to make a comma the first character of each line - except the first (to get a valid JS array). The code show above checks whether the value is true or false - if it is false, the comma is set, if it is true, the value is changed to false.

As the calling function sets the value to true, the first line will not get a comma - but the value will be changed to false - so all the rest of the lines will have a comma as the first character.

Additional functionality for existing markers

%IFEQ, %IFNEQ - control whether a section should be generated

The IFEQ and IFNEQ markers work exactly as usual. However, new options for specifying the comparator have been added.

Format (for all formats, you can specify IFNEQ instead of IFEQ):

1: /(%IFEQ-GETVALUE-XPathExpression=CompareValue)

2: /(%IFEQ-@AttributeName=CompareValue)

3: /(%IFEQ-$name=CompareValue)

1: In this case, the value of the node specified by the XPathExpression is compared to the CompareValue). The XPathExpression can be either absolute or relative to the current element in the XML document.

2: This is a shorthand notation of the former format. The value of the attribute specified by the AttributeName (on the current element) is compared to the CompareValue.

3: This retrieves the value written to memory by a %SET marker. This value is compared to the CompareValue. The value can have been set by a parent PageGenerator.

Samples

1: In the MAIN.js meta template in the wsystandardpage folder, you can find the following block:

/(%IFNEQ-GETVALUE-./SourceCodes/SourceCode[@plex_name="wsyproperties"]/literal=)
    /(%IFNEQ-GETVALUE-./SourceCodes/SourceCode[@plex_name="wsyproperties"]/literal={})
       
Ext.merge(/(PAGEIMPL), /(%GETVALUE-./SourceCodes/SourceCode[@plex_name="wsyproperties"]/literal));
    /(%ENDIF)
/(%ENDIF)

This checks whether the current Page element scopes a wsyproperties SourceCode element (under a SourceCodes element) - and whether the literal value is blank or {}. If the Page element doesn't contain such a SourceCode subelement - or if it only contains blank or {} - the line before the /(%ENDIF) statements will not be processed.

When evaluating the Page shown below, the first %IFNEQ will return true - as the Page does contain a non-blank SourceCodes/SourceCode/literal element for a wsyproperties source code.

The second %IFNEQ will return false as the value is {}.

So in this case, the Ext:Merge... line will not be created.

2: In the meta template DETAILFIELDS.input.js in the WSY_GENERAL_DEFINITIONS folder, which is used to create definitions for all input fields for each detail event except for the hidden fields - you can find the following code:

/(%IFEQ-@plex_hidden=false)
    /(%INCLUDE-FIELD?suffix=input_/[@wsyfieldtype]&templatefolder=WSY_FIELD_DEFINITIONS)
 /(%ENDIF)

This script marker checks whether the current Field element in the XML document has a value of false - if it has the %INCLUDE marker is processed, otherwise not.

So if the two Field elements shown below are processed, the field named SecondUUID will be handled, while the field named Signature will not:

3: See the %SET  example above

More information