Difference between revisions of "Variable Tag in QPR UI"

From Mea Wiki
Jump to navigation Jump to search
Line 13: Line 13:
 
** '''uri''': Escaping suitable for full url's. Implements JavaScript encodeUri() function. (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURI)
 
** '''uri''': Escaping suitable for full url's. Implements JavaScript encodeUri() function. (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURI)
 
** '''uricomponent''': Escaping suitable for url address pars such as parameters. Implements JavaScript encodeUriComponent() function. (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent)
 
** '''uricomponent''': Escaping suitable for url address pars such as parameters. Implements JavaScript encodeUriComponent() function. (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent)
* '''jsonpath''': Contains a JSON path expression (more information: https://github.com/json-path/JsonPath). Context variable value is expected to contain a JSON value and instead of replacing the whole JSON value, the JSON path expression is evaluated for the JSON value and the result is replaced. (will be used in future)
 
  
 
Examples:
 
Examples:
* <#variable name="variable1">
+
<pre>
* <#variable name="variable1" escape="json">
+
<#variable name="variable1">
* <#variable name="someJsonDataVar" jsonpath="$.store.book[0].title">
+
<#variable name="variable1" escape="json">
 +
</pre>
  
 
=== Short syntax for variables ===
 
=== Short syntax for variables ===
Line 26: Line 26:
  
 
Notes:
 
Notes:
* In the short syntax, it's not possible to use parameters, such as escaping.
+
* In the short syntax, it's not possible to use parameters, i.e. the escaping.
 
* If the referred variable contains spaces, it's not possible to use the short syntax.
 
* If the referred variable contains spaces, it's not possible to use the short syntax.
  
 
[[Category: QPR UI]]
 
[[Category: QPR UI]]

Revision as of 07:36, 26 January 2018

Variable tag references to a context variable, i.e. when the tag is evaluated, the tag is replaced by the context variable value. The value is taken from the effective context of that UI element, where the tag resides. When the referenced context variable value changes, the UI element, which setting contain the variable tag, is also refreshed. Variable tag is not able change the context variable value. Also system context variables can be used.

If the referenced context variable doesn't exist, an error is caused.

Variable tag contains following parameters:

  • name: Name of the referenced context variable. This parameter is mandatory.
  • escape: Determines which escaping or encoding is added to the context variable value when the value is used. This parameter is needed, so that the value is compatible with its context, e.g. inside string literal quotation marks. Following values can be used:
    • none: No escaping (default value)
    • json: Escaping suitable for JSON string literals (characters to escape: " \ and escape charater: \)
    • javascript: Escaping suitable for JavaScript string literals (characters to escape: " ' \ and escape charater: \)
    • xml: Escaping suitable for xml text nodes (characters to escape: < > & " ' and resulting strings: &lt; &gt; &amp; &quot; &apos;)
    • html: Encoding performed by the following JavaScript code: $('<div/>').text("textToEncode").html(). Html encoding is needed when a text is put in a html code and the text should not be interpreted as html.
    • uri: Escaping suitable for full url's. Implements JavaScript encodeUri() function. (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURI)
    • uricomponent: Escaping suitable for url address pars such as parameters. Implements JavaScript encodeUriComponent() function. (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent)

Examples:

<#variable name="variable1">
<#variable name="variable1" escape="json">

Short syntax for variables

There is also the following short syntax to refer to variables:

  • <#var1> is same as <#variable name="var1">
  • {#var1} is same as <#variable name="var1">

Notes:

  • In the short syntax, it's not possible to use parameters, i.e. the escaping.
  • If the referred variable contains spaces, it's not possible to use the short syntax.