Skip to main content

Text token source code

For those wishing to learn how to code text tokens, we'll need to take a look at the raw code – the text tokens themselves. Below is the raw code of the example text.

This map shows {=metricTypeMetadata?metricType=2105&returnValue=helpText}, for {child-area-label} within the {authority-label}. There are {=value?metricType=1803} houses in the {authority-label}, of which {=value?metricType=2105} contain unemployed adults with no dependent children. {child-area-label} has {=value?metricType=2105&area={child-area-identifier}} households containing unemployed adults with no dependent children, which equates to a {=percent?metricType=2105&area={child-area-identifier}&with={parent-area-identifier}} share of all households containing unemployed adults with no dependent children within {authority-label}.

The first token – {=metricTypeMetadata?metricType=2105&returnValue=helpText} – is asking for metadata for a certain metric type. From the token, you can see that it will return the help text for metric type 2105. We could choose to return the help text for any metric type, or alternatively could ask for different metadata altogether, e.g. the label, source, or collection.

The second token – {child-area-label} – is asking for the name of the ward the report covers, simply to denote the area we're interested in.

The penultimate token – {=percent?metricType=2105&area={child-area-identifier}&with={parent-area-identifier}} – is asking for the value of a ward's metric as a percentage of its share in the authority, similar to a simple percentage calculation. We can define any area within another area, e.g. the ward's share in the country.

You may have noticed that there are two main types of text token available: fields and functions. Fields return distinct values, e.g. proper nouns, and are relative to the organisation (and ward, if selected) that the report is covering. Functions also return distinct values, e.g. percentages or counts, but have their own attributes (or parameters) that alter the result.

For example, an Authority token (field) will always return the authority covered by the report; whereas a Metric Value token (function) can return the authority's count of households from 2010, 2011, or 2012 depending on the attribute you choose.

Functions have a strict syntax that enables them to work. First, the token is defined by name after the equals character. Following this, a question mark denotes that parameters come next, and each parameter is separated by an ampersand. Fields can be used within functions as parameters, you'll simply need to include them in their parenthetical braces.