2
votes

I'm building a site using Orchard CMS and creating my own custom modules. I have been following a couple of tutorials and so-far-so-good.

I don't understand how the .ShapeHelper() method works and it's giving me a little trouble.

The following code, from my Driver file, works perfectly fine and generates my view on the front-end.

protected override DriverResult Display(SubscribersFormPart part, string displayType, dynamic shapeHelper)
        {    
            // setup model
            part.DateStamp = System.DateTime.Now;
            return ContentShape("Parts_SubscribersForm", () => shapeHelper.DisplayTemplate(TemplateName: "Parts/SubscribersForm", Model: part, Prefix: Prefix));
        }

However, I have seen on other tutorials that rather than DisplayTemplate the name of the part/view is used instead..which is what I would rather as especially when using the Shape Tracing module it's getting a little confusing seeing "DisplayTemplate" (as in the image below..) rather than a more recognisable name

enter image description here

I have tried simply changing my method to:

protected override DriverResult Display(SubscribersFormPart part, string displayType, dynamic shapeHelper)
        {    
            // setup model
            part.DateStamp = System.DateTime.Now;
            return ContentShape("Parts_SubscribersForm", () => shapeHelper.Parts_SubscribersForm(TemplateName: "Parts/SubscribersForm", Model: part, Prefix: Prefix));
        }
  • notice the "Parts_SubscribersForm()" - though when I do this I get the following error...

enter image description here

I believe it is to do with where my views are located, though I also believe I have these in the correct folders that Orchard requires. This is my folder structure where my views are concerned...

enter image description here

Can anybody point me in the right direction - where I can use my parts name in the shapeHelper method, rather than "DisplayContent"?

1

1 Answers

7
votes

Put your display template directly inside Views folder (/Views/Parts.SubscribersForm.cshtml), not inside DisplayTemplates. Orchard, by convention, scans Views folders only when looking for shape templates. That EditorTemplates subfolder, on the other hand, holds templates for part editors, ie. those shapes returned from driver Editor methods.

What is that dynamic shapeHelper thing? In short - it's a shape factory. When you call eg. shapeHelper.SomeShape(Foo: 1, Bar: "baz"), it returns a shape object that corresponds to a SomeShape.cshtml template, with a dynamic model containing properties Foo and Bar. That template has to reside somewhere in Views folder of a module or theme. That's more or less all the magic.

If you want to understand shapes more - it's a good starting point: http://docs.orchardproject.net/Documentation/Accessing-and-rendering-shapes.