0
votes

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?

2

2 Answers

0
votes

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

0
votes

Try:

<a name="@Model.Header.Items[0].Title" />

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:

<a name="@Model.Title" /> 

in your template alternate.