简体   繁体   English

在EKTRON CMS的“目标内容”小部件中添加新的RuleTemplate

[英]Add new RuleTemplate in the Targeted Content Widget in EKTRON CMS

I have an ektron8.7 application. 我有一个ektron8.7应用程序。 I need to Customize the Targeted Content Widget (add a new RuleTemplate). 我需要自定义目标内容小部件(添加新的RuleTemplate)。 But I dont know how to achieve this. 但我不知道如何实现这一目标。 Please anyone help me for this 请任何人帮我

Please find this link and answer me. 请找到此链接并回答我。

In root\\App_Code folder just create a class file for example MyRuleTemplate.cs 在root \\ App_Code文件夹中,只需创建一个类文件,例如MyRuleTemplate.cs

namespace Ektron.Com.Helpers
{  
    public class MyRuleTemplate : RuleTemplate
    {

        private StringOperatorField _fieldOperator = null;

        public MyRuleTemplate ()
            : base("My First RuleTemplate")
        {
        _fieldOperator = new StringOperatorField("operator", "operator", "");
        }        
        /// <summary>
        /// Evaluating the rule template condition set in the widget
        /// </summary>
        /// <param name="rule"></param>
        /// <returns></returns>
        public override bool Evaluate(Rule rule)
        {
            //write the code for evaluate
        string op = rule.Values["operator"];
            string visitorCountry = string.Empty;
            string ruleCountry = rule.Values["name"];

            try
            {
                string IP = HttpContext.Current.Request["remote_addr"];
                if (!string.IsNullOrEmpty(HttpContext.Current.Request["ip"]))
                    IP = HttpContext.Current.Request["ip"];
                else if (!string.IsNullOrEmpty(HttpContext.Current.Session["ipaddress"].ToString()))
                    IP = HttpContext.Current.Session["ipaddress"].ToString();
                var userData = Ektron.Cms.UserContext.GetLocationInfo(IP);
                visitorCountry = userData.CountryCode;
            }
            catch (Exception ex)
            {
                Ektron.Cms.EkException.LogException(ex, System.Diagnostics.EventLogEntryType.Error);
            }

            return _fieldOperator.Evaluate(visitorCountry, op, ruleCountry);
        }

    private Dictionary<string, Field> _fields = null;
        public override Dictionary<string, Field> Fields
        {
             get
            {
                if (_fields == null)
                {
                    _fields = new Dictionary<string, Field>();
                    this.AddField(_fieldOperator);
                    List<LocalizableValue> countryFields = new List<LocalizableValue>();
                    countryFields.Add(new LocalizableValue("US", "United States"));
                    countryFields.Add(new LocalizableValue("DE", "Germany"));
                    countryFields.Add(new LocalizableValue("CA", "Canada"));
                    countryFields.Add(new LocalizableValue("FR", "France"));
                    _fields.Add("name", new EnumField(new LocalizableValue("name", "name", ""), countryFields));
                }
                return _fields;
            }
        }


        /// <summary>
        /// Text which will be displayed in the condition
        /// </summary>
        public override string Text
        {
            get
            {
                return "Custom Country {operator} {name}";
            }
        }
        /// <summary>
        /// Title of the rule template
        /// </summary>
        public override string Title
        {
            get
            {
                return "Custom Country";
            }
        }


    }
}

Then, in \\widgets\\TargetedContent.ascx.cs inside the method AddAllRuleTemplates() just add a reference to the newly added custom rule template MyRuleTemplate as AddRuleTemplate(new MyRuleTemplate()); 然后,在AddAllRuleTemplates()方法内的\\ widgets \\ TargetedContent.ascx.cs中,只需添加对新添加的自定义规则模板MyRuleTemplate的引用作为AddRuleTemplate(new MyRuleTemplate());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM