...
For example, if a user, or group of users, should be presented with an initial table of contents for the map when they start a particular Weave client then the “toc” tag in that client configuration can be setup in such a way that the value for the name of the toc model to use can be provided by a user attribute.
Code Block |
---|
|
<toc ref="${user.toc}"/> |
Note this example assumes that a user attribute called “toc” has been associated with all users.
In the above example if the value for the “toc” attribute for the current user is “main” then the above would be the equivalent of
Code Block |
---|
|
<toc ref="main"/> |
Default Values
If you can’t, or don’t to want to, set a value for an attribute for all users you can specify a default value for the attribute directly in the config, for example, if we wanted to use “main” as the default toc model to use but have some users use something different then you would use the following format
Code Block |
---|
|
<toc ref="${user.toc|main}"/> |
so if one user had the value “custom” for the toc attribute it would be equivalent to
Code Block |
---|
<toc ref="custom"/> |
and if another user did not have a toc attribute at all it would be equivalent to
Code Block |
---|
<toc ref="main"/> |
Converting Values
Weave will try and guess the type of the value, either the attribute value or the default value, and convert the value to that type, using the same rules that the config file reader uses when initially reading the values from the XML files, and as such there may be times when the conversion is incorrect, for example, if the value of the attribute is “1234” Weave will convert that to the number 1234, for example
Code Block |
---|
<tag value="${user.number}"/> |
would result in the following object
Code Block |
---|
{tag: {value: 1234}} |
If the value is supposed to be a string and not a number then you can override this by appending a colon followed by a format, for example, if the value of the user.number
attribute is 1234 but you need tag.value
to be a string you can explicitly specify the type of the value like:
Code Block |
---|
<tag value="${user.number:string}"/> |
would result in the following object
Code Block |
---|
|
{tag: {value: "1234"}} |
And this is the same but providing a default in case the user does not have a number
attribute
Code Block |
---|
<tag value="${user.number|1234:string}"/> |
Note that type conversion only applies when the entire value is replaced by the user attribute, if the user attribute replacement is only part of the final value then it will always be treated as a string and the format will be ignored, for example
Code Block |
---|
|
<item text="Number: ${user.number:float}"/> |
would be
Code Block |
---|
|
{item: {text: "Number: 1234"}} |