How to override list rendering

Topics: Customizing Orchard, Troubleshooting, Writing themes
Developer
Feb 17, 2011 at 10:43 PM

Hi,

I'm very new on Orchard so please forgive me if I'm asking something that should be trivial.

I created a new content type NewsItem with the Containable and Common parts so that I can include NewsItems in a list.
I also created a custom theme.

I figured out how I can customize the rendering of each NewsItem, but what I can't  figure out is how to customize the rendering of the beginning and the end of the list.
I see that for a list the <ul> element is being used, but I need to add a CSS class to that element (e.g. <ul class="newsitems">...<ul>.

So how should I do that? (I'm still trying to get used to the file naming schemes).

Thanks,

Skywalker

Developer
Feb 18, 2011 at 1:51 AM

Oh never mind, it's simply a matter of creating a List.cshtml file in my Views folder.

Developer
Feb 18, 2011 at 1:12 PM

Hmm.. if I override List.cshtml I screw up the Adm screens (e.g. the list of Content Types will not display).
If I add a Content-List.cshtml view to my Views folder (Themes/MyCustomTheme/Views/Content-List.cshtml), that template is not being used.

So my question remains: how can one override the rendering of a list?

I need to display the list title at the top of the page.

Feb 23, 2011 at 11:59 AM
sfmskywalker wrote:

if I override List.cshtml I screw up the Adm screens (e.g. the list of Content Types will not display).

My first intention was to say that this cannot happen because the Admin screen has its very own theme -- but I just tried it out and you are right.

Developer
Feb 23, 2011 at 10:48 PM

@Mspring: Thanks for checking. So does anyone know how to fully customize the list rendering, what filename to use? Also, is there some documentation explaining how the List ViewModel looks like?

Aug 19, 2011 at 5:13 AM

Hi,

I can only seem to be able to override the List by URL, i.e. List-url-Homepage.cshtml.

I tried to override it for the ContentType I was displaying but it doesn't seem to work. For a content type of HomepageHero I tried.

List-HomepageHero.cshtml

But this doesn't work.

Aug 19, 2011 at 5:04 PM

There doesn't appear to be an alternate for lists specific to the content type being "listed"...but I bet you could add one pretty easily! On this page, there is a section at the end called "Adding alternates through code." I think you could follow this example to tap into builder.Describe("List"), to add an alternate named List__xxxnameOfContentTypeBeingListedxxx, or something like that, and then you would be able to use your List-HomepageHero.cshtml.

I don't know offhand how exactly you would determine what the content type being listed was, but I would think you'd be able to determine it pretty easily by hooking up a debugger to your new shape table provider. I also don't know for a fact that "List" is what you would describe...but, this is where I would start.

One other note - you can use shape tracing to view all alternates available for a shape, they are listed on the "Shape" tab, underneath "Alternate". Viewing this list of alternates is a good way to tell if doing something like creating a List-HomepageHero.cshtml would work. In this case, the absence of List-HomepageHero from the list would have indicated that adding a List-HomepageHero.cshtml would not work.

Jul 5, 2012 at 8:20 AM

Hi Skywalker,

Did you ever solve this problem? If so, do you want to share it? (I'm having the same problem, can't seem to render the List's title without screwing up something else...)