如何在Sitecore的自定义标记 [英] how to create a custom token in sitecore

查看:339
本文介绍了如何在Sitecore的自定义标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个自定义标记的地方,如果在富文本编辑器领域的用户输入特定文本,该文本将显示一个值。所以说,用户输入@@测试仪一样,今天是一个月@@测试仪,在富文本编辑器领域。我有C#试图找到Sitecore的范围内的任何富文本编辑器领域@@测试仪,如果发现标记找到匹配,其中文本将被替换标题字段令牌。因此,即:

I am trying to create a custom token where, if a user inputs certain text in a rich text editor field, that text will display a value. So say the user inputs @@tester like, "Todays month is @@tester" in a rich text editor field. I have c# trying to find @@tester in any rich text editor field within sitecore, and if it finds that token to find that token in a title field that matches where the text is to be replaced. So ie:

Item Name = token
Item ID = {06912058-6U9A-4BBF-BAE3-9306974EBE68}
Title = @@tester
Content (rich text editor) = February

我到目前为止有:

namespace LonzaWeb.Pipeline.RenderField
{
public class AddToken
{
    public void Process(RenderFieldArgs args)
    {
        Item currentItem = Sitecore.Context.Item;

        if ((args.FieldTypeKey == "rich text") && currentItem.TemplateID.ToString() == "{06912058-6U9A-4BBF-BAE3-9306974EBE68}")
        {

            var tItem = currentItem.Fields["Title"].ToString();

            if (tItem != null) {
                Regex regex = new Regex(tItem);
                Match match = regex.Match(tItem);
            }
        }
    }
}
}

此外,我想使用正则表达式模式匹配。我加入这个到webconfig文件,以确保它看起来它。

Also I am trying to use RegEx pattern matching. I have added this into the webconfig file to make sure it looks for it.

推荐答案

扩展< renderField> 管道可能是一个更好的办法去

Extending the <renderField> pipeline is probably a better way to go.

一个新类型可以被提供有其自己的加工方法。类型被处理的场可以​​与RenderFieldArgs.FieldTypeKey进行检查。该物业fieldValue方法可以为每个支持的标记值进行更新。

A new type can be provided with its own Process method. The type of the field being processed can be checked with the RenderFieldArgs.FieldTypeKey. The FieldValue property can be updated with values for each supported token.

在该管道将产生的ARGS传递到线下一个处理器每个处理器。我会GetTextFieldValue之后添加此补丁。

Each processor in the pipeline will pass the resulting args to the next processor in line. I would add this patch after GetTextFieldValue.

http://www.sitecore.net/learn/blogs/technical-blogs/sitecorebetter/posts/2013/06/extending-the-sitecore-renderfield -pipeline.aspx

http://www.sitecore.net/learn/blogs/technical -blogs /约翰 - 西Sitecore的-博客/职位/ 2011/08 /替换令牌功能于富文本字段,使用最Sitecore的-ASPNET,cms.aspx

这篇关于如何在Sitecore的自定义标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆