Page Variables

From KynetxDocs

Jump to: navigation, search

KRL has the ability to make use of variables set on the page. These are called page variables.

To set variables on the page, a JavaScript object called kvars must be declared on the page:

<script type=text/javascript>
var kvars = {};
</script>

For maximum flexibility, this will typically be done in the page header

After the object has been declared, variables are set as follows:

<script type=text/javascript>
kvars.foo = 5;
kvars.bar = 'fizz';
kvars.exsiting_value = existing_js_var
</script>

The names following kvars., sich as foo are the page variable names.

These variables are accessed in KRL using a data source (see Declarations) that is formatted as follows:

page:var(<arg>)

where <arg> is an expression that evaluates to a string matching one of the page variable names.

A page variable can be used anywhere other data sources are used.

Page Variable Examples

A page variable in query

ruleset 10 {
    rule test0 is active {
        select using "/test/" setting()
        pre {}     

	if page:var("zip") like "83*" then
	   alert("You're coming from Idaho!") 

    }
}

A page variable in pre block

ruleset 10 {
    rule test0 is active {
        select using "/test/" setting()
        pre {
      	    zip = page:var("zip");
	}     
        float("absolute", "top: 10px", "right: 10px",
                 "/cgi-bin/weather.cgi?zip=" + zip);

    }
}
 
Personal tools