Back to Contents


Template Instructions

Topics

Back to the top


Genero Web Client Namespace

A Genero Web Client template instruction is prefixed by "gwc". The Genero Web Client processes the template instruction and generates new HTML code.

Syntax

<tag gwc:instruction="expression" ... >
...
</tag>

Notes

  1. tag is an HTML tag
  2. instruction is any template instruction
  3. expression is a template expression

Back to the top


Template Instructions

Element Instructions

 GWC Template Instruction Description
 gwc:snippet-root Delimit a snippet.

Attribute Instructions

 GWC Template Instruction Description
 gwc:define Define a variable to be used in the current tag or the children tags.
 gwc:condition Test the condition.
 gwc:repeat Repeat the children tags.
 gwc:replace Replace the entire tag.
 gwc:attributes Dynamically change an attribute of the current HTML tag.
 gwc:content Replace the text between the tags.
 gwc:omit-tag Suppress the surrounding tag after instructions in the children tags have been processed.
 gwc:marks Associate custom data to the element

With Genero Web Client instructions, as with XML, you can write attributes in any order. The processing of instructions, however, is interpreted in the order listed above, from the highest priority to the lowest. For example, once gwc:replace has been executed, there is no material to achieve the gwc:content processing.

Back to the top


snippet-root instruction

Replace the XHMTL DIV element by the rendering of the component. Snippet-root instructions are typically found in snippet XHTML files. See Application Rendering for more information on snippet files.

Syntax

<gwc:snippet-root>
  ...

</gwc:snippet-root>

Example

<gwc:snippet-root>
  <input type="text" readonly="readonly" class="gField gEdit"
   gwc:marks="
   field [CID];
   currentFieldStyle [CID,'gCurrentField'];
   modifiable isModifiable?[CID]:null;
   "
   gwc:attributes="
   class _tpl_+(isModifiable ? '':' gDisabled')+(color?' gColor_'+color:'')+(hidden!=2?'':' gHidden');
   value value;
   size width;
   maxLength maxLength || null;
   title comment;
   "
  />
</gwc:snippet-root>

This defines the rendering of an Edit field.

Back to the top


define instruction

The define instruction declares a local variable that can be used in the HTML tag (the current element) and in its child elements. This variable is undefined outside of the current element.

Syntax

<tag gwc:define="var expression [; ...]" ...>
...
</tag>

Notes

  1. var is the variable name
  2. expression is a template expression

Example

<div gwc:define="i menu">

i is set to the current item of a menu.

Back to the top


condition instruction

If the expression is TRUE, render the element. If the expression is FALSE, remove the tag and its children.

Syntax

<tag gwc:condition="expression" ...>
...
</tag>

Notes

  1. expression is a template expression
  2. When using expressions in a gwc:condition instruction, verification is done on the value of the expression. The condition is true if the following test is true:
     
     Expression Value Type Test
    Boolean Expression value is true.
    Numeric Expression value is not 0. (zero)
    String String is not empty or "0". (zero)
    Template path with identified node The identified element exists (i.e. formfield[edt1]).
    Template path with value The value is not empty if it is a string, or 0 if it is a numeric or boolean value (i.e. formfield[edt1]/id).

Back to the top


repeat instruction

For a specified collection, iterate through the collection and repeat the element, once per item in the collection.

Syntax

<tag gwc:repeat="elt eltList">
    statements
</tag>

Notes

  1. eltList is the list of elements to loop on (the collection of elements)
  2. elt is an element of eltList
  3. statements are statements repeated for each element elt in the collection eltList
  4. See repeat template paths for special template paths used with a gwc:repeat instruction

Example

<div gwc:repeat="item menu/actions">
  <a href="..." gwc:condition="item/text"
     gwc:define="text item/text"      
     gwc:attributes="href string:${document/URL}?${item/id}" 
     gwc:content="text">Input</a>
</div>

Displays the text of each action of a menu as an HTML link.

Repeat instruction template paths

The following table lists special template paths for use with a gwc:repeat instruction. For more information on template paths, see Template Paths for the Snippet-Based Rendering Engine.

 Template Path Type Component AUI object
 repeat object    
 repeat/elt object    
 Template Path Type Description Attribute Type
 repeat/elt/length attribute Get the length of the repeat sequence (the number of elements in the sequence). number
 repeat/elt/index attribute Get the index of the current element in the sequence, starting with 0 (zero). number
 repeat/elt/first attribute Test if the current repeat element is the first element of the sequence boolean
 repeat/elt/last attribute Test if the current repeat element is the last element of the sequence boolean
 repeat/elt/even attribute Test if the current repeat element is an even element of the sequence boolean
 repeat/elt/odd attribute Test if the current repeat element is an odd element of the sequence boolean

Notes

  1. elt is a repeat instruction element.

Back to the top


replace instruction

Replace the HTML tag (current element and its children) with the value of a template expression.

Syntax

<tag gwc:replace="expression" ...>
...
</tag>

Notes

  1. expression can be any template expression

Example

<div gwc:replace="window"></div>

The DIV tag is replaced by the application window.

Back to the top


attributes instruction

This instruction dynamically sets a value to an attribute of the current tag. If the attribute does not exist, it will be created. If it exists, its value will be changed.

Syntax

<tag gwc:attributes="att expression [; ...] " ...>
...
</tag>

Notes

  1. att is the attribute name
  2. expression is the attribute value. Notice there is no equal sign (=) between the attribute name and the value being assigned to it.

Example

<form action="..." method="post" gwc:attributes="action document/URL ; method string:get">

The action attribute is set to the document URL and the method attribute to get.

Back to the top


content instruction

Replace the element content (between the HTML tags) with the value of a template expression.

Syntax

<tag gwc:content="expression" ...>
...
</tag>

Notes

  1. expression can be any template expression

Example

<div id="gForm-div" gwc:content="form" />

The content of the div tag is set to the generated code of the current form.

Back to the top


omit-tag instruction

If the expression evaluates to TRUE, replace the element by its content. If the expression is FALSE, remove the element.

Syntax

<tag gwc:omit-tag="expression"...>
...
</tag>

Notes

  1. expression is any valid expression

Example

<div gwc:content="formfield[edt1]/value" gwc:omit-tag="true"></div>

This displays the value of the form field "edt1" and removes the DIV tag.

Back to the top


marks instruction

Associates data with the current element, in order to be used by JavaScript on the client side.

Syntax

<tag gwc:marks="mkp expression [; ...] " ...>
   ...
</tag>

Notes

  1. mkp is the mark-up element name
  2. expr is any valid expression

Example

<gwc:snippet-root>
  <input type="text" readonly="readonly" class="gField gEdit"
   gwc:marks="
   field [CID];
   currentFieldStyle [CID,'gCurrentField'];
   modifiable isModifiable?[CID]:null;
   "
   gwc:attributes="
   class _tpl_+(isModifiable ? '':' gDisabled')+(color?' gColor_'+color:'')+(hidden!=2?'':' gHidden');
   value value;
   size width;
   maxLength maxLength || null;
   title comment;
   "
  />
</gwc:snippet-root>

This defines the rendering of an Edit field.

Back to the top