Token Encoders
Under certain circumstances, you may want a token value to be encoded in order to make it "safe" for use (meaning that it won't cause errors due to invalid characters). For example, a URL stored as data may contain characters that are actually invalid in a Logi page, or a session variable value may contain characters that are invalid when processed using JavaScript, or a user may enter non-ASCII characters into a text box. Encoding these characters avoids errors that might otherwise result.
Encoders can be used with @Data, @Local, @Request, and @Session tokens. The notation for a token with an encoder included takes this format:
@<TokenType>!<EncoderType>.<Identifier>~
Two "token encoders" are available: one that makes values safe for URLs ( !Url ), by applying HTML URL encoding, and one that makes values safe for use with JavaScript ( !Js ), by applying UTF-8 encoding. Like other aspects
of tokens, the encoder names are case-sensitive.
A new token encoder ( !Json ) has been addded for use with JSON data. It encodes the characters, such as double-quotes and line feeds, that are invalid in JSON data strings. An example use-case is encoding data entered by a user into an Input Text Area control prior to sending it in an array of JSON data to a web service using REST.
Here are some examples of them in use:
Original Value | Token with Encoder | Resulting Value |
---|---|---|
http://www.logixm.com\test | @Data!Url.SiteAddress~ | http%3a%2f%2fwww.logixml.com%5ctest |
www.xyz.co.uk?ra=1&id=56 | @Session!Url.Redirect~ | www.xyz.co.uk%3fra%3d1%26id%3d56 |
Rain and/or snow | @Request!Js.Weather~ | Rain and\x2for snow |
<b>Topics</b> | @Local!Js.Headings~ | \x3cb\x3eTopics\x3c\x2fb\x3e |
My "dog" has fleas | @Request!Json.inpText~ | My \"dog\" has fleas |
Encoders allow you to very selectively encode data right at the point in the definition where it will be used.