Yeast engine API documentation

YST.Util namespace

Defines several utility functions that template designers may use in Yeast templates.

 

Function summary
Back to top

YST.Util.isEmptyArray (name: String, target: Object)

Checks if a certain target object has an undefined, null or empty array named 'name' as property.

YST.Util.isUndefined (name: String, target: Object)

Checks if a certain object property named 'name' is undefined.

YST.Util.updateNode(nodeId: String)

Re-process a Yeast element of id nodeId.

YST.Util.setTemplateInNode(template: String, target: HTMLElement)

Set the Yeast code, stored in template as a String, as the innerHTML of the target element and process this element.

YST.Util.setTemplateInNodeById(template: String, targetId: String)

Set the Yeast code, stored in template as a String, as the innerHTML of the element whose id is targetId and process this element.

 

Function detail
Back to top

YST.Util.isEmptyArray (name: String, target: Object)

Checks if a certain target object has an undefined, null or empty array named 'name' as property. Notice that the parameter corresponds to the array name, not to the array itself.

If the target object is null, then the existence of an undefined, null or empty global array variable is tested.

parameter   type description
name String name of the target property (must of array type) or global array
target Object object to which the array belongs. Optional.

Return

true if the target object does not have a property named 'name', or this property is null, or this property is not an array or the array length is 0.


YST.Util.isUndefined(name: String, target: Object)

Checks if a certain object property named 'name' is undefined. Notice that the parameter corresponds to the variable name, not to the variable itself.

If the target object is null or undefined, then a global variable will be checked.

parameter   type description
name String name of the object property or global variable name
target Object object to which the property belongs. Optional.

Return

true if the target object has not got a property named 'name'; true if there is no global variable named 'name'.


YST.Util.updateNode(nodeId: String)

Re-process a Yeast element. The element must have an id (id HTML attribute). The element must be marked with the yst="live" (or yst="ajax") processing instruction.

parameter   type description
nodeId String id of the element to be re-processed

YST.Util.setTemplateInNode(template: String, target: HTMLElement )

Set the Yeast code, stored in template as a String, as the innerHTML of the target element and process this element.

Example: being

<script yst="model">
age = 30;
</script>

and

<div id="container"></div>

The following code inserts the template in the container element:

var templ = "I am $age$ years old."
function process() {
  var e = document.getElementById("container");
  YST.Util.setTemplateInNode(templ, e);
}

parameter   type description
template String Yeast code
target HTMLElement element that will contain the Yeast code.

YST.Util.setTemplateInNodeById(template: String, targetId: String )

Set the Yeast code, stored in template as a String, as the innerHTML of the element whose id is targetId and process this element and process this element.

Example: being

<script yst="model">
age = 30;
</script>

and

<div id="container"></div>

The following code inserts the template in the container element:

var templ = "I am $age$ years old."
function process() {
  YST.Util.setTemplateInNodeById(templ, "container");
}

parameter   type description
template String Yeast code
targetId String id of the element that will contain the Yeast code.