Newer Version Available
Using Expressions in Tokens
Cross-Referencing Tokens
To reference one token’s value in another token’s definition, wrap the token to be referenced in standard expression syntax.
1<!-- force:base tokens (SLDS standard tokens) -->
2<aura:tokens>
3 ...
4 <aura:token name="colorBackground" value="rgb(244, 246, 249)" />
5 <aura:token name="fontFamily" value="'Salesforce Sans', Arial, sans-serif" />
6 ...
7</aura:tokens>1<!-- defaultTokens.tokens (your tokens) -->
2<aura:tokens extends="force:base">
3 <aura:token name="mainColor" value="{! colorBackground }" />
4 <aura:token name="btnColor" value="{! mainColor }" />
5 <aura:token name="myFont" value="{! fontFamily }" />
6</aura:tokens>You can only cross-reference tokens defined in the same file or a parent.
Expression syntax in tokens resources is restricted to references to other tokens.
Combining Tokens
1<!-- defaultTokens.tokens (your tokens) -->
2<aura:tokens>
3 <aura:token name="defaultHorizonalSpacing" value="12px" />
4 <aura:token name="defaultVerticalSpacing" value="6px" />
5</aura:tokens>1/* myComponent.css */
2.THIS div.notification {
3 margin: token(defaultVerticalSpacing + ' ' + defaultHorizonalSpacing);
4 /* more styles here */
5}You can mix tokens with strings as much as necessary to create the right style definition. For example, use margin: token(defaultVerticalSpacing + ' ' + defaultHorizonalSpacing + ' 3px'); to hard code the bottom spacing in the preceding definition.
The only operator supported within the token() function is “+” for string concatenation.
For example, don’t separate the size and unit into separate tokens.
1<!-- DO NOT DO THIS! -->
2<aura:token name="v24" value="24" />
3<aura:token name="px" value="px" />If you concatenate the tokens, the CSS doesn’t work as you expect.
1.THIS { font-size: token(v24+px); }The result is font-size: 24, though you might expect it to be font-size: 24px.
Instead, define a size and unit in one token for this use case.
1<aura:token name="v24" value="24px" />