mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-23 04:43:35 +08:00
Adding ability to override the content of a shape
- Using ShapeDispayingContext.ChildContent to force the HmlString to render --HG-- branch : dev
This commit is contained in:
@@ -145,6 +145,35 @@ namespace Orchard.Tests.DisplayManagement {
|
||||
Assert.That(result.ToString(), Is.EqualTo("Hi there!"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RenderPreCalculatedShape() {
|
||||
var displayManager = _container.Resolve<IDisplayManager>();
|
||||
|
||||
var shape = new Shape {
|
||||
Metadata = new ShapeMetadata {
|
||||
Type = "Foo"
|
||||
}
|
||||
};
|
||||
|
||||
shape.Metadata.OnDisplaying(
|
||||
context => {
|
||||
context.ChildContent = new HtmlString("Bar");
|
||||
});
|
||||
|
||||
var descriptor = new ShapeDescriptor {
|
||||
ShapeType = "Foo",
|
||||
};
|
||||
descriptor.Bindings["Foo"] = new ShapeBinding {
|
||||
BindingName = "Foo",
|
||||
Binding = ctx => new HtmlString("Hi there!"),
|
||||
};
|
||||
|
||||
AddShapeDescriptor(descriptor);
|
||||
|
||||
var result = displayManager.Execute(CreateDisplayContext(shape));
|
||||
Assert.That(result.ToString(), Is.EqualTo("Bar"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RenderFallbackShape() {
|
||||
var displayManager = _container.Resolve<IDisplayManager>();
|
||||
|
@@ -7,6 +7,6 @@
|
||||
|
||||
@using (Html.BeginFormAntiForgeryPost()) {
|
||||
@Html.ValidationSummary()
|
||||
// Model is a Shape, calling Display() so that it is rendered using the most specific template for its Shape type
|
||||
// Model is a Shape, calling Display() so that it is rendered using the most specific template for its Shape type
|
||||
@Display(Model)
|
||||
}
|
@@ -10,6 +10,7 @@ namespace Orchard.DisplayManagement.Implementation {
|
||||
public class ShapeDisplayingContext {
|
||||
public dynamic Shape { get; set; }
|
||||
public ShapeMetadata ShapeMetadata { get; set; }
|
||||
public IHtmlString ChildContent { get; set; }
|
||||
}
|
||||
|
||||
public class ShapeDisplayedContext {
|
||||
|
Reference in New Issue
Block a user