Sitecore 轮询模块示例代码

发布于 2024-12-20 09:41:23 字数 290 浏览 1 评论 0原文

我安装并配置了轮询模块,使其工作正常。我正在开发的网站将在页面上有一个投票实例,作为左栏或右栏项目。民意调查将设置在单独的文件夹中。在页面项目上,将有一个多列表字段,该字段将指向“投票”文件夹,用户可以选择他们选择的任何投票。该文件夹还将包含不同的子布局,可以选择这些子布局来显示在导轨上。我有一些自定义代码,它将查看上述多列表字段并显示这些铁路项目。

我不知道如何以编程方式显示投票。我还没有找到任何代码示例,也不知道在哪里设置子布局。我应该将其设置在投票模板本身上,然后让使用代码来显示它吗?我怎样才能在代码中实现这一点?任何代码示例都会有帮助。

I installed and configured the Poll Module to work fine. The website I am working on will have a Poll instance on a page either as a left rail or a right rail item. The Polls would be setup in a separate folder. On the page item there will be a multilist field which will point to the Polls folder and the user can select whichever poll they choose to. The folder will also contain different sublayouts which will could be selected to be displayed on the rail. I have some custom code which will look at the above mentioned multilist field and show these rail items.

I don't know how to display a Poll programmatically. I haven't found any code samples and also not sure where to set the sublayout. Should I set it on the Poll template itself and then let use code to display it? How can I achieve this in code? Any code samples would be helpful.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

执着的年纪 2024-12-27 09:41:23

希望您这次能接受答案,我为您写了以下内容(基于 OMS 投票模块:

读出您的项目上的字段:

 Sitecore.Data.Fields.ReferenceField selectedPoll = (Sitecore.Data.Fields.ReferenceField)Sitecore.Context.Item.Fields["Poll"];

获取投票项目:

 if (selectedPoll.TargetItem != null)
            {
                Item pollItem = selectedPoll.TargetItem;

                if (pollItem != null)
                { 

检查投票是否打开或关闭并放置:

 Sitecore.Data.Fields.CheckboxField pollClosed = (Sitecore.Data.Fields.CheckboxField)pollItem.Fields["Closed"];

                    if (pollClosed.Checked == false)
                    {
                        // Set the header of the snippetBlock
                        ltPollHeader.Text = pollItem.Name;

                        PollVotingSublayout pollSublayout = (PollVotingSublayout)LoadControl("/sitecore modules/Shell/Poll Module/Controls/PollVotingSublayout.ascx");
                        pollSublayout.Attributes.Add("sc_parameters", "PollPath=" + pollItem.Paths.FullPath);
                        pollSublayout.CurrentPoll = (PollItem)pollItem;
                        this.pollRegion.Controls.Add(pollSublayout);

                        phPollSnippet.Visible = true;

                        int blockPos = 0;

                        if (snippetField != null)
                        {
                            if (snippetField.GetItems().Any())
                            {
                                blockPos = 1;
                            }
                        }

                        string cssClass = String.Empty;

                        if (blockPos == 0)
                        {
                            cssClass = "snippetColHomeFirst";
                        }

                        this.SetClass("snippetColHome", cssClass);
                    }   

希望您可以用这个片段来弥补一些东西,祝你好运!

Hoping that you will this time accept the answer, I wrote the following for you (based on the OMS Poll module:

Read out the field on your item:

 Sitecore.Data.Fields.ReferenceField selectedPoll = (Sitecore.Data.Fields.ReferenceField)Sitecore.Context.Item.Fields["Poll"];

Get the pollItem:

 if (selectedPoll.TargetItem != null)
            {
                Item pollItem = selectedPoll.TargetItem;

                if (pollItem != null)
                { 

Check if the poll is opened or closed and place:

 Sitecore.Data.Fields.CheckboxField pollClosed = (Sitecore.Data.Fields.CheckboxField)pollItem.Fields["Closed"];

                    if (pollClosed.Checked == false)
                    {
                        // Set the header of the snippetBlock
                        ltPollHeader.Text = pollItem.Name;

                        PollVotingSublayout pollSublayout = (PollVotingSublayout)LoadControl("/sitecore modules/Shell/Poll Module/Controls/PollVotingSublayout.ascx");
                        pollSublayout.Attributes.Add("sc_parameters", "PollPath=" + pollItem.Paths.FullPath);
                        pollSublayout.CurrentPoll = (PollItem)pollItem;
                        this.pollRegion.Controls.Add(pollSublayout);

                        phPollSnippet.Visible = true;

                        int blockPos = 0;

                        if (snippetField != null)
                        {
                            if (snippetField.GetItems().Any())
                            {
                                blockPos = 1;
                            }
                        }

                        string cssClass = String.Empty;

                        if (blockPos == 0)
                        {
                            cssClass = "snippetColHomeFirst";
                        }

                        this.SetClass("snippetColHome", cssClass);
                    }   

Hope that you can make up something using this snippets. Good luck!

一个人的旅程 2024-12-27 09:41:23

sitecore 域上应该有一个名为“poll”的用户帐户。该帐户通常由投票内部使用。在该帐户的评论中注明:“请不要删除该帐户”。该帐户应具有 Sitecore 最小页面编辑器角色。我不知道轮询用户凭据,但您可能会发现,通过使用反射器或打开 cs 文件,您可以通过下载源代码来获取该凭据。

There should be a user account called "poll" on the sitecore domain. This account is normally used internal by the poll. In the comment of this account is stated: "Please do not remove this account". the account should have the Sitecore Minimal Page Editor role. I don't know the poll user credentials, but you might find that by either using reflector or opening cs files that you can get by downloading the source.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文