It is now possible to replace part(s) of a string using a StyleBook expression(s). When these string expressions are evaluated by the StyleBook compiler, the part of the string that uses a StyleBook expression will be replaced by value of the expression. To include StyleBook expressions in a string, we use the following notation:
"...%{...}%..."
where the characters enclosed between" %{ " and "}%" form a StyleBook expression. These expressions are known as "in-place interpolations. "
For example, the string "lb-%{$parameters.appname}%-svc" is a string expression with in-place interpolation of a StyleBook expression. The value of string expression depends on the value of the interpolation expression. Consider that $parameters.appname is assigned with "app1." Then, the string expression evaluates to lb-app1-svc. This allows the values to be not hard-coded in string expressions, but rather be evaluated based on the user-defined values.
A practical use case of in-place interpolations is to parameterize policy expressions in StyleBooks. Consider a scenario where you want to write a policy expression that checks if the HTTP URL contains a specific word, say, "jpeg".
For this, you write a policy expression as follows: "HTTP.REQ.URL.CONTAINS(\\"jpeg\\")".
Now, if you want to parameterize the object in the HTTP URL, you can add a string parameter in the StyleBook, say, $parameters.url-object. The policy expression should be written based on this parameter. To do that, you use string concatenation to achieve the result. The expression would look like:
str("HTTP.REQ.URL.CONTAINS(\\"" + $parameters.url-object + "\\")")
If $parameter.url-object is assigned "csv", the above expression will evaluate to "HTTP.REQ.URL.CONTAINS(\\"csv\\")". However, this expression is not easy to read. To make this parameterization easy to read and understand, you can use in-place interpolations.
The expression with in-place interpolation is now:
str("HTTP.REQ.URL.CONTAINS(%{quotewrap($parameters.url-object)}%)")
In the above expression, you used an interpolation expression that adds the inner-quotes around the value of the $parameters.url-object. The result of this expression is same as the above, but, it looks more intuitive and closer to the actual result.