Orchard Shape Wrapper

2019-09-11 09:13发布

问题:

I'm following the Orchard documentation on Wrappers but couldn't wrap my head around it. http://docs.orchardproject.net/Documentation/Understanding-placement-info#Wrapper

According to the documentation, we were to create Wrapper.HtmlContent.cshtml and insert the following in it.

<div class="htmlWrapperContent">
    @Model.Html
</div>

But what is Model.Html? Is it a Shape? I know Model is the Shape itself. Html is not a built-in property of Shape or IShape so I figure it must be some custom property done through code, for example shapeHelper.My_Shape(Html: "Hello World")?


Let's start from the beginning with an illustration of what I'm trying to achieve. I have done the following:

Placement.info

<Placement>
    <Place My_Shape="Content:before;Wrapper=My_Wrapper" />
</Placement>

My.Shape.cshtml

<div class="myShape">
    @* let's pretend that the line below prints "Hello World" *@
    @Model.Html
</div>

My.Wrapper.cshtml

<div class="htmlWrapperContent">
    @* what should I be putting here? *@

    @* I have tried the following *@

    @* #1 *@
    <div class="myShape">
        @Model.Html
    </div>
    @* Obviously this works but then why would I use a wrapper to do this? I might as well just surround `My.Shape.cshtml` with `<div class="htmlWrapperContent"></div>` above. *@

    @* #2 *@
    @Display(Model)
    @* This doesn't work because circular reference. IIS killed itself. *@

    @* #3 *@
    @DisplayChildren(Model)
    @* Since `Model._items` is empty, this doesn't print anything. *@
</div>

My expectation of how the page should look like

<div class="htmlWrapperContent">
    <div class="myShape">
        Hello World
    </div>
</div>

So my question is, how should My.Wrapper.cshtml look like to meet my expectation?

回答1:

Shortly after posting my question, I found the answer here

Orchard - Wrappers for Fields

So, the wrapper should be

My.Wrapper.cshtml

<div class="htmlWrapperContent">
    @Display(Model.Metadata.ChildContent)
</div>

The Orchard documentation could use some improvements.