Mike Robbins

Sitecore Developer Blog

Follow me on GitHub

Sitecore Replace Tokens Command

Quite often when developing Sitecore sites, as I'm optimising templates I add additional fields and tokens into the standard values. This means for already created items based on the updated template there are unexpanded $token variables in the content item. The same issue is present if you reset a content item to standard values, the tokens are adding into the content item rather than the calculated value.

Therefore I've developed a new Sitecore module that adds a new command into the content editor to replace all tokens in the current item.

Mike Reynolds has also got a great blog post on using Sitecore PowerShell to replace tokens also. http://sitecorejunkie.com/2015/02/15/expand-tokens-on-items-using-a-sitecore-powershell-extensions-toolbox-script/

Replace Tokens Command

Replace Tokens Command

The below code is the heart of logic behind the component. We create an instance of MasterVariablesReplacer and then call ReplaceItem(item) on the current context item.

Sitecore Marketplace

https://marketplace.sitecore.net/Modules/Replace_Tokens_Command.aspx?sc_lang=en

Source On GitHub

https://github.com/komainu85/TokenReplacementCommand