根据 Sitecore CMS 中的某些条件动态更改上下文元素

发布于 2024-09-10 17:37:42 字数 302 浏览 2 评论 0原文

我在 Sitecore CMS 下拥有用户控制权。它有一些控件绑定到上下文的某些字段。例如:

<sc:text runat="server" field="HomePage_WelcomeText"></sc:text>

我有基于同一模板的不同内容项,我需要在 PageLoad() 中更改其中一些内容的上下文。例如,如果 URLReferer 具有特定值,我希望在上下文中具有特定内容项。

有什么提示吗?

I have user control under Sitecore CMS. It has some controls bound to some fields of context. For example:

<sc:text runat="server" field="HomePage_WelcomeText"></sc:text>

I have different content items based on the same template and I need to change context to some of them in PageLoad(). For example, if URLRefferer has certain value I want to have certain content item in context.

Any hints?

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

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

发布评论

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

评论(1

分分钟 2024-09-17 17:37:42

sc:text 控件有一个名为 Item 的公共属性,它采用 Sitecore.Data.Items.Item。因此,为您的控件提供一个 ID 属性,然后在 Page_Load 上您可以根据需要动态设置该 Item 属性。

<sc:text id="myTextControl" runat="server" field="HomePage_WelcomeText" />
protected void Page_Load(object sender, EventArgs e)
{
    Sitecore.Data.Items.Item myItem = Sitecore.Context.Database.GetItem("/sitecore/content/home");
    myTextControl.Item = myItem;
}

The sc:text control has a public property called Item that takes a Sitecore.Data.Items.Item. So, give your control an ID attribute, then on Page_Load you can dynamically set that Item property as needed.

<sc:text id="myTextControl" runat="server" field="HomePage_WelcomeText" />
protected void Page_Load(object sender, EventArgs e)
{
    Sitecore.Data.Items.Item myItem = Sitecore.Context.Database.GetItem("/sitecore/content/home");
    myTextControl.Item = myItem;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文