Replies: 7 comments 6 replies
-
|
Shape is a building block for Orchard Core display management. A shape can be composed of many other shapes. To keep it simple analogous to Here's my basic understanding - I hope that would help you understand better. Shape
ShapeMetadata
Shape Template or Views
[Shape] attribute
// Basic example of Shape
var parentShape= new Shape(); // Just for illustration, Use ShapeFactory to create shape
parentShape.Metadata.Type = "TypeA"; // Rendered using TypeA.cshtml
parentShape.PropertyA = "Parent"; // Accessed as Model.PropertyA inside TypeA.cshtml shape template
var anotherShape= new Shape();
anotherShape.Metadata.Type = "TypeB"; // Rendered using TypeB.cshtml
//Named shape
anotherShape.Metadata.Name = "childShape";
anotherShape.PropertyB = "Child"; // Accessed as Model.PropertyB inside TypeB.cshtml shape template
parentShape.Add(anotherShape);
dynamic a = parentShape.PropertyA;
// Get Named shape as dynamic property
dynamic b = parentShape.childShape.PropertyB;
// Or with Named function
parentShape.Named("childShape").PropertyB;
// Following code will render TypeA.cshtml or TypeA.liquid or call C# method TypeA having [shape] attribute.
@await DisplayAsync(parentShape)ShapeResultIt is a shape builder factory returned by a DisplayDriverCalled by DisplayManager - It returns AlternateAlternate is a Shape Templates (Views) for the Shape. WrapperWrapper is a shape template(Views) for the Shape - wraps extra html around original shape . Shape MorphingIt's technique to target different shape template for given shape by changing it's Type. var shape= new Shape(); // Just for illustration, Use ShapeFactory to create shape
shape.Metadata.Type = "TypeA";
shape.PropertyA = "A";
// Render Shape Template TypeA.cshtml
@await DisplayAsync(shape)
shape.Metadata.Alternates.Clear();
shape.Metadata.Wrappers.Clear();
shape.Metadata.Type = "TypeB";
// Render Shape Template TypeB.cshtml
@await DisplayAsync(shape);
|
Beta Was this translation helpful? Give feedback.
-
|
this should go in the docs.
|
Beta Was this translation helpful? Give feedback.
-
|
@ns8482e thanks for informative explanation, I think we should add them to docs if we miss some or write a blog post that we can refer too Thanks so much Niraj |
Beta Was this translation helpful? Give feedback.
-
|
@ns8482e does the shape work with the Admin UI ?, or It only works with the Site UI only ?. |
Beta Was this translation helpful? Give feedback.
-
|
It is as simple as saying that since Orchard Core uses a composition design pattern with it's Content Types. Content Types needed to use Dynamic typing. So, it's ViewModels needed to also be Dynamic (see what inherits ShapeViewModel). Shape can be used in a lot of different places where Dynamic objects are used to build up the UI with the DisplayManager which defines things like Drivers (DisplayDrivers, BuildEditorDrivers) which has been implemented to allow to dynamically bind dynamic ViewModels to a controller action. Simple explanation is that a common ViewModel will generally be strongly typed and pass only one Content Type (for example) but @sebastienros needed to make this smarter to not need to create a different Editor / Display for each of these dynamic ViewModels. Also, it would have not made any sense to use a strongly typed ViewModel for these since a Content Type definition is dynamic and can be changed on runtime. So from there started having the need of a Shape which is a dynamic UI part that can be containing a Content Part, Content Field ... ... which can be morphed when you want to see it in it's details, summary view |
Beta Was this translation helpful? Give feedback.
-
|
This is a new video about Shape https://www.youtube.com/watch?v=adJ9n9y_6P0 |
Beta Was this translation helpful? Give feedback.
-
|
Hi Everyone, as Orchard Core newbie I can completely understand @dodyg 😊 Has the explanation made by @ns8482e here, and @Skrypt here been added to the official documentation? I'm looking at the reference guide and I can't find it. Thank you |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I've implemented and deployed several websites using OrchardCore. I've written a lot of templates, a couple of custom modules and interacted with shapes in many places but I fundamentally don't understand what it is.
I've read this but most of the details really just fly over my head.
Beta Was this translation helpful? Give feedback.
All reactions