Paul
Paul

Reputation: 12440

Wrapper for custom Content Part - Orchard CMS

Using the Orchard admin I created a new Content Part called 'Spotlight Wrapper' with 3 HTML fields. I then created a Content Type Called 'Template 1' and assigned 'Spotlight Wrapper' to it. I then created a new 'Template 1' content item called 'Home Page'. I then created a file called Fileds_Contrib.Html-Spotlight Wrapper.cshtml to wrap each HTML field in the 'Spotlight Wrapper' with an and this is working. I have now added:

<Place Parts_SpotlightWrapper="Content:before;Wrapper=Parts_SpotlightWrapper" />

And created :

Views\Parts.SpotlightWrapper.cshtml

in an attempt to wrap the entire 'Spotlight Wrapper' Content Part in a but cannot seem to get it to work?

Upvotes: 3

Views: 2839

Answers (1)

Piotr Szmyd
Piotr Szmyd

Reputation: 13366

You declared a wrapper which I guess would lead to circular reference, as you try to wrap the Parts_SpotlightWrapper shape with itself. Wrappers are just separate pieces of Razor (cshtml) code that act as a parent for a given shape.

To achieve the behavior you want you should create a separate .cshtml file (eg. MyWrapper.cshtml) containing the necessary wrapper HTML code and attach it to your existing part like this:

<Place Parts_SpotlightWrapper="Content:before;Wrapper=MyWrapper" />

The wrapper code could look eg. like this:

<ul>
    @Display(Model.Child)
</ul>

Btw - Try to look how it's done in Orchard.Widgets. There are two wrappers Widget.Wrapper and Widget.ControlWrapper that wrap the Widget shape. Declarations of those are not inside the Placement.info file (as you did), but hardcoded in Shapes.cs shape definition, though the final effect is perfectly the same. The technique with the Placement.info was just introduced later as a shortcut.

HTH

Upvotes: 2

Related Questions