如何在orchard cms中以编程方式创建投影小部件? [英] How to create a projection widget programmatically in orchard cms?

查看:92
本文介绍了如何在orchard cms中以编程方式创建投影小部件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好



我在我的模块中使用以下代码创建了一个查询:



Hi

I have created a query in my module with this code:

var myName = "something" 
var theQuery = _contentManager.Create("Query"); 
theQuery.As<TitlePart>().Title = myName + "Query"; 
var filterGroupRecord = new FilterGroupRecord(); 
var filterRecord = new FilterRecord() 
{
Category = "Content", Type = "ContentTypes", Description = myName , Position = 1, State = "<Form><Description>" + myName + "</Description>    <ContentTypes>" + myName + "</ContentTypes></Form>"
}; 
filterGroupRecord.Filters.Insert(0, filterRecord); 
theQuery.As<QueryPart>().FilterGroups.Clear(); 
theQuery.As<QueryPart>().FilterGroups.Insert(0, filterGroupRecord); 





我知道创建一个投影小工具我应该在代码下面使用:





And I know to create a projection widget I should use below code :

var theProjectionWidget = _contentManager.Create("ProjectionWidget"); 
theProjectionWidget .As<WidgetPart>().Title = myName + "ProjectionWidget"; 
theProjectionWidget .As<WidgetPart>().RenderTitle = false; 
theProjectionWidget .As<WidgetPart>().Zone = "Content"; 
theProjectionWidget .As<WidgetPart>().Position = "1"; 
theProjectionWidget .As<WidgetPart>().LayerPart.Name = myName;









但我不知道如何将上述查询分配给这个新的投影小部件。

如何将查询ID分配给ProjectionPart.QueryLayoutRecordId ??? !!





这些链接到这个讨论在stackoverflow& codeplex:



http://stackoverflow.com/questions/28514224/how-to-create-a-projection-widget-programmatically-in-orchard-cms



https://orchard.codeplex.com/discussions/580735

推荐答案

经过一些代码和调试的摔跤后,我找到了解决问题的方法。

任何有问题的人都可以使用这个代码:



After some wrestling with code and debug I found solution for my question.
Anybody with my problem can use this code:

theProjectionWidget.As<ProjectionPart>().Record.QueryPartRecord = new QueryPartRecord(){

            ContentItemRecord = theQuery.As<QueryPart>().ContentItem.Record,
            FilterGroups = theQuery.As<QueryPart>().FilterGroups,
            Id = theQuery.As<QueryPart>().Id,
            Layouts = theQuery.As<QueryPart>().Layouts,
            SortCriteria = theQuery.As<QueryPart>().SortCriteria

        };


这篇关于如何在orchard cms中以编程方式创建投影小部件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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