Orchard CMS:为列表项创建书签
我们正在 Orchard CMS 中使用“列表”内容类型创建一个页面。我们想在列表顶部添加一些超链接,这些超链接将向下跳转到列表中的特定项目。
我们特别不想链接到列表项的单个页面,而是跳转到列表中的位置,并且因为列表项是使用相同的 View 部分呈现的,所以我们当然不能只是硬对书签进行编码。
我们已经在 VS 中自定义了 View Part,并且知道列表项标题是使用代码生成的
@Display(Model.Header)
: h1>且< a>标签围绕标题,如下所示:
< h1 shape-id=“5”>< a href="/Orchard/Contents/Item/Display/36" shape-id="5" >营销< /a>< /h1>
但是,我们找不到一种方法让 Display() 方法包含“name=”子句,然后我们可以将其用作书签。
我们还尝试在现有代码上方添加一个新标签,例如:
< a name="@Model.Header" >< /a >
@Display(Model.Header)
但是,Model.Header 当然是一个对象引用,而不是一些文本,因此失败了。此后,我们迷失了各种方法,试图找到模型对象的属性来获取标题作为文本,但失败了。
必须有一种方法可以重载 Display() 方法以使其包含“name=”子句,有人有任何想法吗?
We're creating a page in Orchard CMS using the 'List' Content Type. We want to add some hyperlinks at the top of the list, that will jump down the page to specific items in the list.
We specifically don't want to just link to the individual page for the list item, but jump down to where it is in the list, and because the list items are rendered using the same View part, we can't of course just hard code the bookmarks.
We've been customising the View Part in VS and know that the list item title is generated using the code:
@Display(Model.Header)
And this generates < h1 > and < a > tags to wrap around the title like this:
< h1 shape-id="5" >< a href="/Orchard/Contents/Item/Display/36" shape-id="5" >Marketing< /a >< /h1 >
However, we can't find a way to get the Display() method to include a 'name=' clause which we can then use as the bookmark.
We've also tried adding a new tag just above the exiting code, e.g.:
< a name="@Model.Header" >< /a >
@Display(Model.Header)
But of course the Model.Header is an object reference, and not some text, so this failed. After this we've got lost with various ways trying to find a property of the Model object to fetch the Title as text but couldn't.
There must be a way to overload the Display() method to get it to include the 'name=' clause, anyone got any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Model.Header 只是一个区域。真正呈现标题的是添加到该区域的形状。您确实应该使用形状追踪(设计器工具模块的一部分)来了解形状的层次结构。您不需要“重载显示方法”。您需要的是覆盖呈现标题的形状的模板(不是 Model.Header 而是其中的某些内容)。
您可能想阅读以下内容: http://weblogs.asp.net/bleroy/archive/2011/03/27/take-over-list-rendering-in-orchard.aspx 和这个http://weblogs .asp.net/bleroy/archive/2011/05/23/orchard-list-customization-first-item-template.aspx
Model.Header is just a zone. What really renders the title is a shape that was added to that zone. You should really use Shape Tracing (part of the Designer Tools module) to understand what the hierarchy of shapes looks like. You don't need to "overload the display method". What you need is to override the template for the shape that is rendering the title (which is not Model.Header but something inside it).
You might want to read this: http://weblogs.asp.net/bleroy/archive/2011/03/27/taking-over-list-rendering-in-orchard.aspx and this http://weblogs.asp.net/bleroy/archive/2011/05/23/orchard-list-customization-first-item-template.aspx
尝试:
它并不漂亮,但当我将其放入我创建的传记内容类型的备用模板(Views/Content-Bio.Summary.cshtml)时,它对我有用。
根据 Bertrand 的建议,您可以尝试:
在模板中替换。
Try:
It's not pretty, but it worked for me when I dropped this in an alternate template for a biography content type I created (Views/Content-Bio.Summary.cshtml).
Based on Bertrand's suggestion, instead you can try:
in your template alternate.