如何访问 Sitecore 子布局的自定义属性?

发布于 2024-12-09 20:21:09 字数 350 浏览 0 评论 0 原文

我想创建一个如下所示的 Sitecore 子布局:

<sc:Sublayout runat="server" ID="slMySublayout" Path="~/layouts/My Sublayout.ascx" MyCustomProperty="some value" />

我希望由于 Sitecore 子布局是从 ASP.NET 用户控件继承的,所以我能够创建一个名为“MyCustomProperty”的公共属性并获取设置的值声明性地用于子布局。但这似乎不起作用。公共属性似乎永远不会使用 ASCX 文件中输入的值进行设置。

有谁知道这是否可能?

谢谢, 科里

I want to create a Sitecore sublayout like the following:

<sc:Sublayout runat="server" ID="slMySublayout" Path="~/layouts/My Sublayout.ascx" MyCustomProperty="some value" />

I was hoping that since a Sitecore sublayout is inherited from an ASP.NET user control that I would be able to create a public property called "MyCustomProperty" and get at the value that was set declaritively for the sublayout. However that doesn't seem to work. The public property never seems to get set with the value entered on the ASCX file.

Does anyone know if this is possible?

Thanks,
Corey

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

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

发布评论

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

评论(1

合约呢 2024-12-16 20:21:10

我想通了。相反 - 你像这样编写你的子布局标签:

<sc:Sublayout runat="server" ID="slMySublayout" Path="~/layouts/My Sublayout.ascx" Parameters="MyCustomProperty=somevalue" />

然后确保你的子布局继承自 SublayoutBase (共享源 - http://trac.sitecore.net/SublayoutParameterHelper/browser/Trunk/Web/UI/Sublayouts/SublayoutBase.cs)。只要您的子布局上有一个名为 MyCustomProperty 的公共属性,那么它就会在加载时正确设置。如果您有多个属性,您可以在“参数”部分中将它们全部设置 - 只需在它们之间使用“&”号即可。

I figured it out. Instead - you write your sublayout tag like this:

<sc:Sublayout runat="server" ID="slMySublayout" Path="~/layouts/My Sublayout.ascx" Parameters="MyCustomProperty=somevalue" />

Then make sure that your sublayout inherits from SublayoutBase (shared source - http://trac.sitecore.net/SublayoutParameterHelper/browser/Trunk/Web/UI/Sublayouts/SublayoutBase.cs). As long as you have a public property on your sublayout called MyCustomProperty, then it will get set correctly at load. If you have multiple properties you can just set them all in the Parameters section – just use an ampersand between them.

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