If you're using Sitecore you're already familiar with the ability to reuse components and content itself through data sources. However, there's an even more granular option you should be aware of.
If you're a content author, this approach can save you potentially hundreds of hours in the long run when large amount of content needs to be updated. For example, say your company name changes and you've written that name on every page you have on your site. Or maybe you've mentioned the CEO's name on dozens of pages. It would be mighty stressful and time consuming if you've forgotten where all those mentions are.
Sitecore Content Tokens to the rescue.
Creating A Content Token
Tokens themselves have changed somewhat from Sitecore 9.3 and now in 10.1 (Sitecore SXA 1.9+) are far easier to create, modify and use throughout your content in a variety of ways.
Locate Content Tokens Data Folder
In your SXA site, head on down to the /<Tenant>/<Site>/Data/Content Tokens
folder.
Insert A Content Token
Right click on the folder and insert a Content Token.
Here we've created one called "CompanyName". By default, both the Key
and Value
are set with the same value.
Let's Update The Value
We can now update the Value
field with the name of the company.
Let's Use It!
Using Content Tokens In Rich Text Editors
Now heres are a couple ways you can go about using that new variable. Open up an item in Experience Editor and open up the Rich Text Editor, or the Rich Text Editor via Content Editor. And look for this symbol. It's called Insert Variable.
You're now presented with a handy popup allowing you to select the variable you just created! Go on, select it.
We can see it shows up a bit different in the editor.
If we examine the HTML, it looks much different again.
<span class="xa-variable" contenteditable="false" data-variableid="{0212C71E-EFF6-4394-95D2-4A9083C7D87E}">CompanyName</span>
It's clearly a bit more complex, but you can see how it's constructed. This same capability is done in Sitecore 9.3, but there are a few more steps involved which we will cover another time.
Using Content Tokens In Fields
You can also use the Content Token in a field. You're by no means limited to just using it in a Rich Text Editor. And it's really simple to do.
Go to any field with a Single-Line Text field or Multi-Line Text field.
By using the format $(variable name)
we can insert that token as needed.
And that's how easy it is. So next time you need to update hundreds of pages, if you've utilized Content Tokens you won't be tearing your hair out because you'll only need to update a single value rather than hundreds or thousands of individual items.