根据打开页面的列表以不同方式呈现页面
我有两个不同页面类型的列表 - NewsItems 和 PressReleases。它们分别显示在一个列表中,并带有指向各个项目的链接。
现在我想将新闻稿项目包含到新闻列表中,并使用新闻项目的样式将它们显示为新闻项目。它们共享新闻模板中使用的“标题”和“正文文本”等属性。
我想向 NewsItems 的 ListPage 提供两组页面不会那么困难,但我不明白如何控制项目页面的呈现。
我想从 NewsItem 或 PressReleaseItem 获取 PageData 对象,并使用 News-Item.aspx 模板显示它(如果在 NewsList 中选择它)。但 EPiServer 将始终使用 PR-Item.aspx 呈现 PressReleaseItem,因为它是在 PageType 设置中耦合的。
有人知道如何做到这一点吗?
编辑:努力澄清:
重要的问题是如何了解“列表父级”并从中选择正确的模板。在 ListPage 中,我可以使用 tompipes 答案分别对 PR 和新闻项目应用不同的外观,但是当选择查看单个项目时,EPi 将以相同的方式呈现 PR-Item-1,无论其“列表父级”如何。这就是问题所在。
I have two lists of different PageTypes - NewsItems and PressReleases. They are displayed in one list each, with links to the individual items.
Now I want to include the press release items into the news list and use the style of the news items to display them as news items. They share properties like "Heading" and "BodyText", which are used in the News Template.
I imagine that it won't be that difficult to feed the NewsItems' ListPage with both sets of pages, but I don't understand how I can control the rendering of the item page.
I would like to take the PageData object from a NewsItem OR a PressReleaseItem and display it using the News-Item.aspx template, if it is selected in a NewsList. But EPiServer will always render the PressReleaseItem with the PR-Item.aspx since it's coupled in the PageType settings.
Anyone know how to accomplish this?
EDIT: An effort to clarify:
The important issue is how to know the "list parent" and choose the right template from that. In the ListPage I can apply different looks on the PR and News items respectively using tompipes answer, but when selecting to see an individual item EPi will render the PR-Item-1 the same way regardless of their "list parent". That's the problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我没有完全遵循您在这里尝试的内容。但我想我明白了它的要点。
为什么不对两种页面类型使用同一个 aspx 模板,而是在后面的代码中使用visible 属性关闭部分。
如果您使用 PageTypeBuilder,您可以使用“is”关键字:
如果您不使用 PTB,您可以使用类似以下内容:
或者
我现在指出,我不喜欢硬编码任何内容,所以我会放置模板名称或 ID 到配置文件中,或起始/根页面上的属性以避免对它们进行硬编码。
让我知道这是否有帮助,或者如果我误解了,请尝试详细说明您的问题。
I'm not following exactly what you are attempting here. But I think I get the gist of it.
Why not use one aspx template for both page types, but in the code behind switch off sections using the visible attribute.
If you are using PageTypeBuilder you could use the "is" keyword:
If you're not using PTB, you could use something like:
or
I'll point out now I'm not a fan of hardcoding anything, so I would place the template name, or ID into a config file, or a property on the start/root page to avoid hardcoding them.
Let me know if this will help, or if I have misunderstood please try elaborate on your issue.
根据模板共享的程度,您可以使用用户控件、占位符甚至不同的母版页以合适的方式切换视图。
要知道何时切换,您可以使用查询字符串参数、会话变量或最好的方式可能是通过 HTTP 引荐来源网址查找并获取列表的 PageData 对象。如果它是空的,您将得到最坏情况的新闻稿渲染。
Depending on how much the templates share you could go with user controls, placeholders or even different masterpages to switch view in a suitable way.
To know when to switch you could use a querystring parameter, session variable or the nicest looking way would probably be to lookup and get the list's PageData object by the HTTP referrer. If it's empty you will get press release rendering as the worst case.
我尝试了很多解决方案,包括向列表链接中的 PR 项目添加查询字符串、在项目模板中获取引用 url 以及用于从 PR 项目自动发布新闻项目的不同类型的事件挂钩(尽管我只看了查看该代码示例),最后得出的结论是,它们都有一些东西告诉我不要走那条路。 (使代码太复杂,或者标记逻辑太难理解等等)
我最终使用了
从另一个EPiServer页面获取数据
,并创建了一个“快捷方式页面类型”,我可以在其中让我的编辑器选择哪个公关项目应用作新闻项目的基础。此快捷方式页面类型称为“PR-as-news-itemPage”,它使用与普通新闻项相同的 aspx 进行呈现:News-Item.aspx。由于没有自己的属性,它将从使用“Fetch...”选择的 PR 项目中获取所有相关数据。
为了呈现 PR 项目及其所有属性,我创建了一个名为 PR-Item.aspx 的普通新页面类型。这将呈现“属性 2”属性,该属性仅由 PR-item.aspx 呈现,而不由 News-Item.aspx 呈现。
(我本来可以更简单,让编辑器使用旧的 News-Item 页面类型并使用“Fetch...”属性,但我在该页面类型中有一些我不想创建的强制属性为此,可选。)
I tried lots of solutions, including the adding of querystring to the PR items in the list links, the getting of referring url in the item template and different types of event hooking for automatic publishing of news items from a PR item (although I only looked at the code samples for that one), and finally came to the conclusion that they all had something that told me not to go that way. (Making the code too complex, or the markup logic too hard to understand and so forth)
I ended up using
Fetch data from another EPiServer page
, and creating a "shortcut pagetype" in which I let my editors pick which PR item should be used as base for a news item.This shortcut pagetype is called "PR-as-news-itemPage" and it is rendered with the same aspx as ordinary news items: News-Item.aspx. Having no properties of its own, it will take all relevant data from the PR item selected with "Fetch..."
To render PR items with all its properties I created an ordinary new pagetype called PR-Item.aspx. This renders the "Attribute 2" property, which is only rendered by PR-item.aspx, and not by News-Item.aspx.
(I could have gone even simpler, by letting the editors use the old News-Item page type and use the "Fetch..." property there, but I have some mandatory properties in that page type which I didn't want to make optional for this sake.)