Generating Shapes with ShapeHelper in Orchard CMS - Type Not Found

梦想与她 提交于 2019-12-08 01:44:39

问题


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

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...

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...

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


回答1:


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.



来源:https://stackoverflow.com/questions/18059888/generating-shapes-with-shapehelper-in-orchard-cms-type-not-found

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!