= Dynamic Expansion

Dynamic expansion is a feature that allows values to be dynamically
expanded at run time. For historical reasons, these string expansions
are called "xlats".

Dynamic expansion is performed via the following syntax:

`%{...}`

Where the `%{` signals the start of a dynamic expansion, and `}`
signals the end of the dynamic expansion.  Dynamic expansions are most
commonly used in xref:type/string/double.adoc[double-quoted strings],
and xref:unlang/expression.adoc[expressions / conditions].

The contents of an expansion can be many things, such as attribute
references, function calls, etc.  The table below gives more examples of expansions.

.Types of Expansions
[options="header"]
|=====
| Keyword                                           | Description
| xref:xlat/attribute.adoc[attributes]              | Expand the value of a named attribute.
| xref:xlat/character.adoc[single character]        | Single character expansions.
| xref:xlat/function.adoc[functions]               | Function call syntax
| xref:xlat/alternation.adoc[condition]             | Conditionally expand a string.
| xref:xlat/builtin.adoc[built-in expansions]       | Functions as string length, tolower, etc...
|=====

Expansions are used inside of
xref:type/string/double.adoc[double-quoted strings] and for the
xref:type/string/backticks.adoc[back-tick quoted strings]

== Character Escaping

Some characters need to be escaped within a dynamically expanded
string `%{...}`. The `%` character is used for variable expansion, so a
literal `%` character can be created by using `%%`.

Other than within a dynamically expanded string, very little character
escaping is needed. The rules of the enclosing string context
determine whether or not a space or `"` character needs to be escaped.
See the ref:type/string/double.adoc[double-quoted strings] and
xref:type/string/backticks.adoc[back-tick quoted strings] pages for more
information.

.Example

[source,unlang]
----
&Reply-Message := "%{User-Name} with a literal %%"
----

// Copyright (C) 2021 Network RADIUS SAS.  Licenced under CC-by-NC 4.0.
// This documentation was developed by Network RADIUS SAS.
