您可以添加在renderField管道一步:
<renderField>
<processor type="Sitecore.Pipelines.RenderField.SetParameters, Sitecore.Kernel"/>
<processor type="Sitecore.Pipelines.RenderField.GetFieldValue, Sitecore.Kernel"/>
<processor type="Sitecore.Pipelines.RenderField.GetTextFieldValue, Sitecore.Kernel"/>
<processor type="Sitecore.Pipelines.RenderField.ExpandLinks, Sitecore.Kernel"/>
<processor type="Sitecore.Pipelines.RenderField.GetImageFieldValue, Sitecore.Kernel"/>
<processor type="Sitecore.Pipelines.RenderField.GetLinkFieldValue, Sitecore.Kernel"/>
<processor type="Sitecore.Pipelines.RenderField.GetInternalLinkFieldValue, Sitecore.Kernel"/>
<processor type="Sitecore.Pipelines.RenderField.GetMemoFieldValue, Sitecore.Kernel"/>
<processor type="Sitecore.Pipelines.RenderField.GetDateFieldValue, Sitecore.Kernel"/>
<processor type="Sitecore.Pipelines.RenderField.GetDocxFieldValue, Sitecore.Kernel"/>
<processor type="Sitecore.Pipelines.RenderField.AddBeforeAndAfterValues, Sitecore.Kernel"/>
<processor type="Sitecore.Pipelines.RenderField.RenderWebEditing, Sitecore.Kernel"/>
<processor type="MyProject.ExpandNVelocityTokens, MyProject"/>
</renderField>
的代碼看起來是這樣的:
public class ExpandNVelocityTokens
{
public virtual void Process(RenderFieldArgs args)
{
if (!ShouldRun())
return;
if (!Sitecore.Context.PageMode.IsPageEditorEditing)
{
args.Result.FirstPart = ExpandVelocityTokens(args.Result.FirstPart);
args.Result.LastPart = ExpandVelocityTokens(args.Result.LastPart);
}
}
protected bool ShouldRun()
{
// In the cheapest possible way - determine if we need to do anything
}
protected string ExpandVelocityTokens(string input)
{
//... do velocity stuff here
}
}
注:此管道運行呈現各個領域,因此是最重要的它速度非常快 - 因此應該儘早開展ShouldRun方法。除非必須,否則在這裏不要做任何昂貴的事情。
看看[這個博客文章](http://www.matthewkenny.com/2013/11/nvelocity-sitecores-original-template-engine/),做同樣的事情。 [重複使用和共享數據](http://sdn.sitecore.net/upload/sitecore6/64/reusing_and_sharing_data-usletter.pdf)指南中還有關於令牌替換的更多信息。 – jammykam
是的。令牌替換正是我所需要的。正如答案中所解釋的那樣。謝謝。 – Ben