Displaying Content Part in Theme View Template

Topics: Customizing Orchard, Writing modules
Editor
Aug 16, 2011 at 12:05 AM

I have created a new content part called "SignupPart" and attached it to my content type. When I let the default rendering template take over for the content type the content part's template renders the content part information correctly. However when I override the content type's default template in my view to customize it, the content part is not rendered. I tried the following but it is not hitting my content part's view template:

In my theme content type override template:

@Display(Model.ContentItem.SignupPart)"

It just renders the text "Model.ContentItem.SignupPart" on the page.

Thanks

Coordinator
Aug 16, 2011 at 12:31 AM

You can only call Display on a Shape. Here, Model.ContentItem.SignupPart must be a Content Part isntance.

Editor
Aug 16, 2011 at 12:33 AM

OK. Then do I just have to manually render the Content Part by hand? How do I render out my content part values?

Coordinator
Aug 16, 2011 at 12:36 AM

Do you really want to customize every thing in your content type ? Because there are solutions to customize only some specific portions of it. Can you explain a little bit more what you are trying to accomplish ?

Editor
Aug 16, 2011 at 12:42 AM

Sure. I wrote a Content Part for a Content Type called "SignUpPart". My content type is built using the CMS and I attach the SignUpPart to the content type after I enable the module. All works fine when I go to the detail page for that content type. It renders the Content Part and the other fields as it should.

Now, I added a new Display Template in my theme for this content type called Content-MyContentType-Detail.cshtml. In it I customize how the fields of the content type and the markup are rendered. Next I would like to render my content part as well with custom markup around the fields of it. Can I just call a @Display method on it or do I need to access the Content Part's properties and render them by hand. For example, <h3>SignUpPart.Property1</h3>

Coordinator
Aug 16, 2011 at 1:32 AM

If you want to customize it, you need to call each specific property.

Editor
Aug 16, 2011 at 1:02 PM

So question for you. In the default view template for my content part I can bind to the view model I created and access everything in the way I want. In the scenario I am in right now I cannot access my View Model or am not seeing how  to. I have my Content Item with all of its Parts. One of the parts is my SignUp Part but when I access it by Model.ContentItem.SignupPart the properties available are not the same as in my view model. Is there a way I can access these? The property I see only has nHibernate type objects.

Sorry if I am not being completely clear. This is my first content part module.

Editor
Aug 16, 2011 at 3:48 PM

There is no way to call Display on your content part from inside a View template? If I am overriding the normal view template for the content type can't I just call Display so my content part is then rendered? I would like to then provide an override template for the content part view template in my theme as well. Maybe not calling the Display method but is there anyway to trigger the rendering of my content part?

Editor
Aug 17, 2011 at 12:22 AM

I would really appreciate someone chiming in here. I think what I am doing is not something too far from what people would want to do if they had a custom content part and then want to override the view template for the content type they are attaching to it. 

I have access to the Content Part when doing this but I need to know how to display the View Model for the content part, or make a call on the content part to render the shape using the view model.

The core system must call something on the attached content parts to have them render.

Aug 17, 2011 at 2:09 PM

The standard way to do this would be to create a content part Driver for your SignupPart, and override the Display method. From there you would return a shape result for which you can provide a view template.