Content management system 存储标题的Orchard自定义令牌

Content management system 存储标题的Orchard自定义令牌,content-management-system,orchardcms,orchardcms-1.6,Content Management System,Orchardcms,Orchardcms 1.6,我有一个像这样的定制果园令牌 public void Describe(DescribeContext context) { context.For("Site", T("Site"), T("Site settings.")) .Token("RootUrl", T("RootUrl"), T("The current site's root url.")); context.For("Topi

我有一个像这样的定制果园令牌

public void Describe(DescribeContext context) 
        {
            context.For("Site", T("Site"), T("Site settings."))
                .Token("RootUrl", T("RootUrl"), T("The current site's root url."));

            context.For("Topic", T("Topic"), T("Topic contents."))
                .Token("Title", T("Title"), T("Title of the topic"));
        }

        public void Evaluate(EvaluateContext context)
        {
            context.For("Site", _orchardServices.WorkContext.HttpContext.Request)
                .Token("RootUrl", token => _orchardServices.WorkContext.HttpContext.Request.Url.GetLeftPart(UriPartial.Authority));

            context.For<IContent>("Topic")
                .Token("Title", content =>
                {
                    int id = content.As<CommentPart>().Record.CommentedOn;
                    var contentItem = _contentManager.Get(id);
                    return contentItem.As<TitlePart>().Title;
                })
                .Chain("Title", "Title", content => 
                {
                    int id = content.As<CommentPart>().Record.CommentedOn;
                    var contentItem = _contentManager.Get(id);
                    return contentItem.As<TitlePart>().Title;
                });
        }

然而这里从来没有人居住过,有人能给我这个黑暗的角落带来一些光明吗?

这里缺少的是背景。评估标记化字符串的代码将提供一个上下文对象,该对象将是对标记进行评估的依据。通常,该上下文中将有一个内容对象,它将被传递到内容令牌的Lambda中。在这里,您告诉系统,如果它在上下文中找到IContent类型的名为“Topic”的内容,它应该由您的逻辑处理。不幸的是,这永远不会发生,因为调用代码没有将这样的对象设置到上下文中

从您的问题来看,您的意图似乎是在添加评论时获得评论的标题。我认为,您可以只做
Content.DisplayText
,但如果您必须开发自己的令牌,请将其附加到内容令牌,而不是构建一个新的根令牌,它不会在您想要的地方得到评估。因此,这将是内容的主题标记

{Topic.Title}