From 30475d2cedcfac08e0f1e0a291c5ab5c0ce5b76b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A1ra=20El-Saig?= Date: Fri, 8 Dec 2023 22:58:05 +0100 Subject: [PATCH 01/32] Add Content property when it's not defined. --- .../TagHelpers/BaseShapeTagHelper.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/OrchardCore/OrchardCore.DisplayManagement/TagHelpers/BaseShapeTagHelper.cs b/src/OrchardCore/OrchardCore.DisplayManagement/TagHelpers/BaseShapeTagHelper.cs index 30688fd3d70..6bf95671b85 100644 --- a/src/OrchardCore/OrchardCore.DisplayManagement/TagHelpers/BaseShapeTagHelper.cs +++ b/src/OrchardCore/OrchardCore.DisplayManagement/TagHelpers/BaseShapeTagHelper.cs @@ -1,3 +1,4 @@ +using Microsoft.AspNetCore.Html; using System; using System.Collections.Generic; using System.Threading.Tasks; @@ -71,6 +72,16 @@ public override async Task ProcessAsync(TagHelperContext tagHelperContext, TagHe } } + if (!properties.ContainsKey("Content")) + { + var content = await output.GetChildContentAsync(useCachedResult: false); + var html = content.GetContent(); + if (!string.IsNullOrWhiteSpace(html)) + { + properties.Add("Content", new HtmlString(html)); + } + } + if (string.IsNullOrWhiteSpace(Type)) { Type = output.TagName; From 299043cbcceaea27676faf9d5caf079be6c41c4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A1ra=20El-Saig?= Date: Fri, 8 Dec 2023 22:59:00 +0100 Subject: [PATCH 02/32] Fix demo controller. For some reason the original code kept crashing, saying something along the lines of IShape doesn't have "Line" method. --- .../OrchardCore.Demo/Controllers/HomeController.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Demo/Controllers/HomeController.cs b/src/OrchardCore.Modules/OrchardCore.Demo/Controllers/HomeController.cs index 00e2a17fc1b..9397b42f618 100644 --- a/src/OrchardCore.Modules/OrchardCore.Demo/Controllers/HomeController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Demo/Controllers/HomeController.cs @@ -104,9 +104,7 @@ public async Task DisplayShape(string contentItemId) return NotFound(); } - var shape = Shape - .Foo() - .Line(contentItem.As().Line); + var shape = await Shape.Foo(Line: contentItem.As().Line); return View(shape); } From f6617069d8d042d5fc38ecdc50ccc65791b7067d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A1ra=20El-Saig?= Date: Fri, 8 Dec 2023 22:59:17 +0100 Subject: [PATCH 03/32] Adding demo content. --- .../OrchardCore.Demo/Views/EmbedContentInShape.cshtml | 5 +++++ .../OrchardCore.Demo/Views/Home/DisplayShape.cshtml | 11 +++++++++++ 2 files changed, 16 insertions(+) create mode 100644 src/OrchardCore.Modules/OrchardCore.Demo/Views/EmbedContentInShape.cshtml diff --git a/src/OrchardCore.Modules/OrchardCore.Demo/Views/EmbedContentInShape.cshtml b/src/OrchardCore.Modules/OrchardCore.Demo/Views/EmbedContentInShape.cshtml new file mode 100644 index 00000000000..3f2360fbede --- /dev/null +++ b/src/OrchardCore.Modules/OrchardCore.Demo/Views/EmbedContentInShape.cshtml @@ -0,0 +1,5 @@ +
+

The content is inserted below this line.

+

@Model.Content

+

The content is inserted above this line.

+
\ No newline at end of file diff --git a/src/OrchardCore.Modules/OrchardCore.Demo/Views/Home/DisplayShape.cshtml b/src/OrchardCore.Modules/OrchardCore.Demo/Views/Home/DisplayShape.cshtml index ea0fa58748b..ea9412edf90 100644 --- a/src/OrchardCore.Modules/OrchardCore.Demo/Views/Home/DisplayShape.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Demo/Views/Home/DisplayShape.cshtml @@ -22,3 +22,14 @@ + + + The inner HTML of the <shape> tag helper is converted into HTML and then passed to the shape as + the IHtmlContent Content model property. + + Even other shapes! + + + + This content is ignored. + \ No newline at end of file From ec33f93c4904ee200ce370fdc1b411161cc20d8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A1ra=20El-Saig?= Date: Fri, 8 Dec 2023 23:02:35 +0100 Subject: [PATCH 04/32] Document spacing. --- .../OrchardCore.Demo/Views/EmbedContentInShape.cshtml | 2 +- .../OrchardCore.Demo/Views/Home/DisplayShape.cshtml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Demo/Views/EmbedContentInShape.cshtml b/src/OrchardCore.Modules/OrchardCore.Demo/Views/EmbedContentInShape.cshtml index 3f2360fbede..d4078d83801 100644 --- a/src/OrchardCore.Modules/OrchardCore.Demo/Views/EmbedContentInShape.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Demo/Views/EmbedContentInShape.cshtml @@ -2,4 +2,4 @@

The content is inserted below this line.

@Model.Content

The content is inserted above this line.

- \ No newline at end of file + diff --git a/src/OrchardCore.Modules/OrchardCore.Demo/Views/Home/DisplayShape.cshtml b/src/OrchardCore.Modules/OrchardCore.Demo/Views/Home/DisplayShape.cshtml index ea9412edf90..99f84ab0405 100644 --- a/src/OrchardCore.Modules/OrchardCore.Demo/Views/Home/DisplayShape.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Demo/Views/Home/DisplayShape.cshtml @@ -32,4 +32,4 @@ This content is ignored. - \ No newline at end of file +
From b18f2f8d53d0c4a2ea853a7f9e03a30613c4d889 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A1ra=20El-Saig?= Date: Wed, 3 Jan 2024 15:55:02 +0100 Subject: [PATCH 05/32] Rename the shape property to HtmlContent from Content to avoid conflict with existing special property. --- .../OrchardCore.Demo/Views/EmbedContentInShape.cshtml | 2 +- .../OrchardCore.Demo/Views/Home/DisplayShape.cshtml | 5 +++-- .../TagHelpers/BaseShapeTagHelper.cs | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Demo/Views/EmbedContentInShape.cshtml b/src/OrchardCore.Modules/OrchardCore.Demo/Views/EmbedContentInShape.cshtml index d4078d83801..d666e109956 100644 --- a/src/OrchardCore.Modules/OrchardCore.Demo/Views/EmbedContentInShape.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Demo/Views/EmbedContentInShape.cshtml @@ -1,5 +1,5 @@ 

The content is inserted below this line.

-

@Model.Content

+

@Model.HtmlContent

The content is inserted above this line.

diff --git a/src/OrchardCore.Modules/OrchardCore.Demo/Views/Home/DisplayShape.cshtml b/src/OrchardCore.Modules/OrchardCore.Demo/Views/Home/DisplayShape.cshtml index 99f84ab0405..5ca153183c8 100644 --- a/src/OrchardCore.Modules/OrchardCore.Demo/Views/Home/DisplayShape.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Demo/Views/Home/DisplayShape.cshtml @@ -25,11 +25,12 @@ The inner HTML of the <shape> tag helper is converted into HTML and then passed to the shape as - the IHtmlContent Content model property. + the IHtmlContent HtmlContent model property. Even other shapes! - + This content is ignored. diff --git a/src/OrchardCore/OrchardCore.DisplayManagement/TagHelpers/BaseShapeTagHelper.cs b/src/OrchardCore/OrchardCore.DisplayManagement/TagHelpers/BaseShapeTagHelper.cs index 6bf95671b85..b53d8e77e93 100644 --- a/src/OrchardCore/OrchardCore.DisplayManagement/TagHelpers/BaseShapeTagHelper.cs +++ b/src/OrchardCore/OrchardCore.DisplayManagement/TagHelpers/BaseShapeTagHelper.cs @@ -72,13 +72,13 @@ public override async Task ProcessAsync(TagHelperContext tagHelperContext, TagHe } } - if (!properties.ContainsKey("Content")) + if (!properties.ContainsKey("HtmlContent")) { var content = await output.GetChildContentAsync(useCachedResult: false); var html = content.GetContent(); if (!string.IsNullOrWhiteSpace(html)) { - properties.Add("Content", new HtmlString(html)); + properties.Add("HtmlContent", new HtmlString(html)); } } From 81a7de8247ed4823e6d7baf77cb67e370fa75ee2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A1ra=20El-Saig?= Date: Wed, 3 Jan 2024 16:02:25 +0100 Subject: [PATCH 06/32] cshtml formatting. --- .../OrchardCore.Demo/Views/Home/DisplayShape.cshtml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Demo/Views/Home/DisplayShape.cshtml b/src/OrchardCore.Modules/OrchardCore.Demo/Views/Home/DisplayShape.cshtml index 5ca153183c8..a812ea05f1c 100644 --- a/src/OrchardCore.Modules/OrchardCore.Demo/Views/Home/DisplayShape.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Demo/Views/Home/DisplayShape.cshtml @@ -30,7 +30,6 @@ Even other shapes! - + This content is ignored. From 3cb0f912f23a5844f85423aec2a1af4eed7fdb44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A1ra=20El-Saig?= Date: Wed, 3 Jan 2024 16:09:40 +0100 Subject: [PATCH 07/32] Fix cshtml mistake. --- .../OrchardCore.Demo/Views/Home/DisplayShape.cshtml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Demo/Views/Home/DisplayShape.cshtml b/src/OrchardCore.Modules/OrchardCore.Demo/Views/Home/DisplayShape.cshtml index a812ea05f1c..4a4cd17faf8 100644 --- a/src/OrchardCore.Modules/OrchardCore.Demo/Views/Home/DisplayShape.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Demo/Views/Home/DisplayShape.cshtml @@ -30,6 +30,7 @@ Even other shapes! - + This content is ignored. From 71f97cf33e54dbc5468e2c389622fdd927b88b16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A1ra=20El-Saig?= Date: Fri, 19 Jan 2024 08:06:08 +0100 Subject: [PATCH 08/32] Replace bare HTML content with a child tag helper. --- .../Views/Home/DisplayShape.cshtml | 20 ++++++++++------ .../TagHelpers/BaseShapeTagHelper.cs | 11 --------- .../TagHelpers/HtmlContentTagHelper.cs | 23 +++++++++++++++++++ 3 files changed, 36 insertions(+), 18 deletions(-) create mode 100644 src/OrchardCore/OrchardCore.DisplayManagement/TagHelpers/HtmlContentTagHelper.cs diff --git a/src/OrchardCore.Modules/OrchardCore.Demo/Views/Home/DisplayShape.cshtml b/src/OrchardCore.Modules/OrchardCore.Demo/Views/Home/DisplayShape.cshtml index 4a4cd17faf8..7ef0bb263b9 100644 --- a/src/OrchardCore.Modules/OrchardCore.Demo/Views/Home/DisplayShape.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Demo/Views/Home/DisplayShape.cshtml @@ -24,13 +24,19 @@ - The inner HTML of the <shape> tag helper is converted into HTML and then passed to the shape as - the IHtmlContent HtmlContent model property. - - Even other shapes! + + The inner HTML of the <html-content name="propertyName"> tag helper (which is a direct child + of the <shape> tag helper) is converted into HTML and then passed to the shape as a model + property. The property's name is the string passed into the name attribute. + + Even other shapes can be included! + - - This content is ignored. + + + If a <html-content> tag helper exists, it takes precedence over any matching attribute of the + <shape> tag helper. This is because child tag helpers are evaluated after the shape is + created, right before it's displayed. + diff --git a/src/OrchardCore/OrchardCore.DisplayManagement/TagHelpers/BaseShapeTagHelper.cs b/src/OrchardCore/OrchardCore.DisplayManagement/TagHelpers/BaseShapeTagHelper.cs index b53d8e77e93..30688fd3d70 100644 --- a/src/OrchardCore/OrchardCore.DisplayManagement/TagHelpers/BaseShapeTagHelper.cs +++ b/src/OrchardCore/OrchardCore.DisplayManagement/TagHelpers/BaseShapeTagHelper.cs @@ -1,4 +1,3 @@ -using Microsoft.AspNetCore.Html; using System; using System.Collections.Generic; using System.Threading.Tasks; @@ -72,16 +71,6 @@ public override async Task ProcessAsync(TagHelperContext tagHelperContext, TagHe } } - if (!properties.ContainsKey("HtmlContent")) - { - var content = await output.GetChildContentAsync(useCachedResult: false); - var html = content.GetContent(); - if (!string.IsNullOrWhiteSpace(html)) - { - properties.Add("HtmlContent", new HtmlString(html)); - } - } - if (string.IsNullOrWhiteSpace(Type)) { Type = output.TagName; diff --git a/src/OrchardCore/OrchardCore.DisplayManagement/TagHelpers/HtmlContentTagHelper.cs b/src/OrchardCore/OrchardCore.DisplayManagement/TagHelpers/HtmlContentTagHelper.cs new file mode 100644 index 00000000000..e22b0b35597 --- /dev/null +++ b/src/OrchardCore/OrchardCore.DisplayManagement/TagHelpers/HtmlContentTagHelper.cs @@ -0,0 +1,23 @@ +using Microsoft.AspNetCore.Html; +using Microsoft.AspNetCore.Razor.TagHelpers; +using System.Threading.Tasks; + +namespace OrchardCore.DisplayManagement.TagHelpers; + +[HtmlTargetElement("html-content", Attributes = "name", TagStructure = TagStructure.NormalOrSelfClosing)] +public class HtmlContentTagHelper : TagHelper +{ + [HtmlAttributeName("name")] + public string Name { get; set; } + public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) + { + if (context.Items[typeof(IShape)] is IShape shape && !string.IsNullOrWhiteSpace(Name)) + { + var content = await output.GetChildContentAsync(useCachedResult: false); + shape.Properties[Name.Trim()] = new HtmlString(content.GetContent()); + } + + _ = await output.GetChildContentAsync(); + output.SuppressOutput(); + } +} \ No newline at end of file From 75fb1907683b097da528ccdd0a906f35396f3b8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A1ra=20El-Saig?= Date: Fri, 19 Jan 2024 08:06:51 +0100 Subject: [PATCH 09/32] Bug fix for html-content with embedded shape. --- .../TagHelpers/BaseShapeTagHelper.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/OrchardCore/OrchardCore.DisplayManagement/TagHelpers/BaseShapeTagHelper.cs b/src/OrchardCore/OrchardCore.DisplayManagement/TagHelpers/BaseShapeTagHelper.cs index 30688fd3d70..dc746e8217c 100644 --- a/src/OrchardCore/OrchardCore.DisplayManagement/TagHelpers/BaseShapeTagHelper.cs +++ b/src/OrchardCore/OrchardCore.DisplayManagement/TagHelpers/BaseShapeTagHelper.cs @@ -126,7 +126,10 @@ public override async Task ProcessAsync(TagHelperContext tagHelperContext, TagHe shape.Metadata.Wrappers.Add(Convert.ToString(output.Attributes["wrapper"].Value)); } - tagHelperContext.Items.Add(typeof(IShape), shape); + // This may overwrite an existing item in the context if shape tag helpers are embedded ito each other (e.g. + // via the tag helper. In this case overwriting doesn't affect the parent tag helper context + // so this is safe. + tagHelperContext.Items[typeof(IShape)] = shape; if (!string.IsNullOrWhiteSpace(Cache)) { From ed31344c7161d452f4507c93950a663446936aec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A1ra=20El-Saig?= Date: Fri, 19 Jan 2024 08:19:41 +0100 Subject: [PATCH 10/32] Demo multiple properties. --- .../Views/EmbedContentInShape.cshtml | 14 +++++++++++++- .../Views/Home/DisplayShape.cshtml | 4 ++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Demo/Views/EmbedContentInShape.cshtml b/src/OrchardCore.Modules/OrchardCore.Demo/Views/EmbedContentInShape.cshtml index d666e109956..398ffb112fc 100644 --- a/src/OrchardCore.Modules/OrchardCore.Demo/Views/EmbedContentInShape.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Demo/Views/EmbedContentInShape.cshtml @@ -1,5 +1,17 @@ -
+@using Microsoft.AspNetCore.Html + +

The content is inserted below this line.

@Model.HtmlContent

The content is inserted above this line.

+ + @if (Model.OtherContent is IHtmlContent otherContent) + { + +
+

Another property called "OtherContent" starts here.

+

@otherContent

+

Another property called "OtherContent" ends here.

+
+ }
diff --git a/src/OrchardCore.Modules/OrchardCore.Demo/Views/Home/DisplayShape.cshtml b/src/OrchardCore.Modules/OrchardCore.Demo/Views/Home/DisplayShape.cshtml index 7ef0bb263b9..0a56b09d2eb 100644 --- a/src/OrchardCore.Modules/OrchardCore.Demo/Views/Home/DisplayShape.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Demo/Views/Home/DisplayShape.cshtml @@ -1,3 +1,4 @@ +@using Microsoft.AspNetCore.Html @model dynamic @addTagHelper "*, OrchardCore.Resources" @addTagHelper "*, OrchardCore.Demo" @@ -31,6 +32,9 @@ Even other shapes can be included! + + You can have multiple, they are just @nameof(IHtmlContent) type shape properties. + From 22241d9db7e0970045b7c12f8de3a9280d090c19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A1ra=20El-Saig?= Date: Fri, 19 Jan 2024 08:26:23 +0100 Subject: [PATCH 11/32] Add extension points to BaseShapeTagHelper for more behavior control in derived classes. --- .../TagHelpers/BaseShapeTagHelper.cs | 28 +++++++++++++++++++ .../TagHelpers/HtmlContentTagHelper.cs | 2 +- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/OrchardCore/OrchardCore.DisplayManagement/TagHelpers/BaseShapeTagHelper.cs b/src/OrchardCore/OrchardCore.DisplayManagement/TagHelpers/BaseShapeTagHelper.cs index dc746e8217c..c73e9d54c75 100644 --- a/src/OrchardCore/OrchardCore.DisplayManagement/TagHelpers/BaseShapeTagHelper.cs +++ b/src/OrchardCore/OrchardCore.DisplayManagement/TagHelpers/BaseShapeTagHelper.cs @@ -71,6 +71,8 @@ public override async Task ProcessAsync(TagHelperContext tagHelperContext, TagHe } } + await OnPropertiesAddedAsync(properties, tagHelperContext, output); + if (string.IsNullOrWhiteSpace(Type)) { Type = output.TagName; @@ -162,10 +164,36 @@ public override async Task ProcessAsync(TagHelperContext tagHelperContext, TagHe await output.GetChildContentAsync(); + await OnDisplayingAsync(shape, tagHelperContext, output); + output.Content.SetHtmlContent(await _displayHelper.ShapeExecuteAsync(shape)); // We don't want any encapsulating tag around the shape output.TagName = null; } + + /// + /// Extension point that may be invoked in a derived class to alter the before the + /// shape is created with them. + /// + protected virtual Task OnPropertiesAddedAsync( + IDictionary properties, + TagHelperContext tagHelperContext, + TagHelperOutput output) => + Task.CompletedTask; + + /// + /// Extension point that may be invoked in a derived class to alter the before it's + /// executed and rendered into HTML. + /// + /// + /// + /// + /// + protected virtual Task OnDisplayingAsync( + IShape shape, + TagHelperContext tagHelperContext, + TagHelperOutput output) => + Task.CompletedTask; } } diff --git a/src/OrchardCore/OrchardCore.DisplayManagement/TagHelpers/HtmlContentTagHelper.cs b/src/OrchardCore/OrchardCore.DisplayManagement/TagHelpers/HtmlContentTagHelper.cs index e22b0b35597..be0a70c71f7 100644 --- a/src/OrchardCore/OrchardCore.DisplayManagement/TagHelpers/HtmlContentTagHelper.cs +++ b/src/OrchardCore/OrchardCore.DisplayManagement/TagHelpers/HtmlContentTagHelper.cs @@ -17,7 +17,7 @@ public override async Task ProcessAsync(TagHelperContext context, TagHelperOutpu shape.Properties[Name.Trim()] = new HtmlString(content.GetContent()); } - _ = await output.GetChildContentAsync(); + await output.GetChildContentAsync(); output.SuppressOutput(); } } \ No newline at end of file From 65653e974f9eb524c06642cc3e48e2b10d79e29e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A1ra=20El-Saig?= Date: Fri, 19 Jan 2024 08:39:07 +0100 Subject: [PATCH 12/32] Spacing and spelling. --- .../TagHelpers/BaseShapeTagHelper.cs | 6 +++--- .../TagHelpers/HtmlContentTagHelper.cs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/OrchardCore/OrchardCore.DisplayManagement/TagHelpers/BaseShapeTagHelper.cs b/src/OrchardCore/OrchardCore.DisplayManagement/TagHelpers/BaseShapeTagHelper.cs index c73e9d54c75..b7c1e64feba 100644 --- a/src/OrchardCore/OrchardCore.DisplayManagement/TagHelpers/BaseShapeTagHelper.cs +++ b/src/OrchardCore/OrchardCore.DisplayManagement/TagHelpers/BaseShapeTagHelper.cs @@ -128,9 +128,9 @@ public override async Task ProcessAsync(TagHelperContext tagHelperContext, TagHe shape.Metadata.Wrappers.Add(Convert.ToString(output.Attributes["wrapper"].Value)); } - // This may overwrite an existing item in the context if shape tag helpers are embedded ito each other (e.g. - // via the tag helper. In this case overwriting doesn't affect the parent tag helper context - // so this is safe. + // This may overwrite an existing item in the context if shape tag helpers are embedded into each other + // (e.g. via the tag helper. In this case overwriting doesn't affect the parent tag helper + // context so this is safe. tagHelperContext.Items[typeof(IShape)] = shape; if (!string.IsNullOrWhiteSpace(Cache)) diff --git a/src/OrchardCore/OrchardCore.DisplayManagement/TagHelpers/HtmlContentTagHelper.cs b/src/OrchardCore/OrchardCore.DisplayManagement/TagHelpers/HtmlContentTagHelper.cs index be0a70c71f7..afdb86b61c7 100644 --- a/src/OrchardCore/OrchardCore.DisplayManagement/TagHelpers/HtmlContentTagHelper.cs +++ b/src/OrchardCore/OrchardCore.DisplayManagement/TagHelpers/HtmlContentTagHelper.cs @@ -20,4 +20,4 @@ public override async Task ProcessAsync(TagHelperContext context, TagHelperOutpu await output.GetChildContentAsync(); output.SuppressOutput(); } -} \ No newline at end of file +} From f8bc3d25d6a4b0d0b8fbddec2a0c1a1568f37df5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A1ra=20El-Saig?= Date: Fri, 19 Jan 2024 08:40:33 +0100 Subject: [PATCH 13/32] Remove duplicate GetChildContentAsync call. --- .../TagHelpers/HtmlContentTagHelper.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/OrchardCore/OrchardCore.DisplayManagement/TagHelpers/HtmlContentTagHelper.cs b/src/OrchardCore/OrchardCore.DisplayManagement/TagHelpers/HtmlContentTagHelper.cs index afdb86b61c7..57d18b84f11 100644 --- a/src/OrchardCore/OrchardCore.DisplayManagement/TagHelpers/HtmlContentTagHelper.cs +++ b/src/OrchardCore/OrchardCore.DisplayManagement/TagHelpers/HtmlContentTagHelper.cs @@ -17,7 +17,6 @@ public override async Task ProcessAsync(TagHelperContext context, TagHelperOutpu shape.Properties[Name.Trim()] = new HtmlString(content.GetContent()); } - await output.GetChildContentAsync(); output.SuppressOutput(); } } From 5e8e5cabbb980f2ec1878aa8b84f279d0de547df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A1ra=20El-Saig?= Date: Sat, 10 Feb 2024 23:48:12 +0100 Subject: [PATCH 14/32] Remove extension points. --- .../TagHelpers/BaseShapeTagHelper.cs | 28 ------------------- 1 file changed, 28 deletions(-) diff --git a/src/OrchardCore/OrchardCore.DisplayManagement/TagHelpers/BaseShapeTagHelper.cs b/src/OrchardCore/OrchardCore.DisplayManagement/TagHelpers/BaseShapeTagHelper.cs index 2395abeb13e..e803035f0d6 100644 --- a/src/OrchardCore/OrchardCore.DisplayManagement/TagHelpers/BaseShapeTagHelper.cs +++ b/src/OrchardCore/OrchardCore.DisplayManagement/TagHelpers/BaseShapeTagHelper.cs @@ -78,8 +78,6 @@ public override async Task ProcessAsync(TagHelperContext tagHelperContext, TagHe } } - await OnPropertiesAddedAsync(properties, tagHelperContext, output); - if (string.IsNullOrWhiteSpace(Type)) { Type = output.TagName; @@ -171,36 +169,10 @@ public override async Task ProcessAsync(TagHelperContext tagHelperContext, TagHe await output.GetChildContentAsync(); - await OnDisplayingAsync(shape, tagHelperContext, output); - output.Content.SetHtmlContent(await _displayHelper.ShapeExecuteAsync(shape)); // We don't want any encapsulating tag around the shape output.TagName = null; } - - /// - /// Extension point that may be invoked in a derived class to alter the before the - /// shape is created with them. - /// - protected virtual Task OnPropertiesAddedAsync( - IDictionary properties, - TagHelperContext tagHelperContext, - TagHelperOutput output) => - Task.CompletedTask; - - /// - /// Extension point that may be invoked in a derived class to alter the before it's - /// executed and rendered into HTML. - /// - /// - /// - /// - /// - protected virtual Task OnDisplayingAsync( - IShape shape, - TagHelperContext tagHelperContext, - TagHelperOutput output) => - Task.CompletedTask; } } From 3db27d567faa6cb81e51ed44ea71e3db4b126016 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A1ra=20El-Saig?= Date: Sun, 11 Feb 2024 01:04:24 +0100 Subject: [PATCH 15/32] Adjust HtmlContentTagHelper to be more similar to other shape child tag helpers such as add-alternate. --- .../TagHelpers/HtmlContentTagHelper.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/OrchardCore/OrchardCore.DisplayManagement/TagHelpers/HtmlContentTagHelper.cs b/src/OrchardCore/OrchardCore.DisplayManagement/TagHelpers/HtmlContentTagHelper.cs index 57d18b84f11..2dbcd8c2a9a 100644 --- a/src/OrchardCore/OrchardCore.DisplayManagement/TagHelpers/HtmlContentTagHelper.cs +++ b/src/OrchardCore/OrchardCore.DisplayManagement/TagHelpers/HtmlContentTagHelper.cs @@ -11,7 +11,9 @@ public class HtmlContentTagHelper : TagHelper public string Name { get; set; } public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) { - if (context.Items[typeof(IShape)] is IShape shape && !string.IsNullOrWhiteSpace(Name)) + var shape = (IShape)context.Items[typeof(IShape)]; + + if (!string.IsNullOrWhiteSpace(Name)) { var content = await output.GetChildContentAsync(useCachedResult: false); shape.Properties[Name.Trim()] = new HtmlString(content.GetContent()); From 25c6805241227a6482599b4a1c9d8401a3dfcdcf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A1ra=20El-Saig?= Date: Sun, 11 Feb 2024 02:04:49 +0100 Subject: [PATCH 16/32] Remove comment. --- .../TagHelpers/BaseShapeTagHelper.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/OrchardCore/OrchardCore.DisplayManagement/TagHelpers/BaseShapeTagHelper.cs b/src/OrchardCore/OrchardCore.DisplayManagement/TagHelpers/BaseShapeTagHelper.cs index e803035f0d6..7a7a6f95e7e 100644 --- a/src/OrchardCore/OrchardCore.DisplayManagement/TagHelpers/BaseShapeTagHelper.cs +++ b/src/OrchardCore/OrchardCore.DisplayManagement/TagHelpers/BaseShapeTagHelper.cs @@ -133,9 +133,6 @@ public override async Task ProcessAsync(TagHelperContext tagHelperContext, TagHe shape.Metadata.Wrappers.Add(Convert.ToString(output.Attributes["wrapper"].Value)); } - // This may overwrite an existing item in the context if shape tag helpers are embedded into each other - // (e.g. via the tag helper. In this case overwriting doesn't affect the parent tag helper - // context so this is safe. tagHelperContext.Items[typeof(IShape)] = shape; if (!string.IsNullOrWhiteSpace(Cache)) From 9d43867b09880be1de820e895c1180b5601d8a24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A1ra=20El-Saig?= Date: Sun, 11 Feb 2024 02:10:32 +0100 Subject: [PATCH 17/32] Rename to add-property. --- .../Views/Home/DisplayShape.cshtml | 16 ++++++++-------- .../TagHelpers/HtmlContentTagHelper.cs | 3 ++- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Demo/Views/Home/DisplayShape.cshtml b/src/OrchardCore.Modules/OrchardCore.Demo/Views/Home/DisplayShape.cshtml index 0a56b09d2eb..c26b6c7c21a 100644 --- a/src/OrchardCore.Modules/OrchardCore.Demo/Views/Home/DisplayShape.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Demo/Views/Home/DisplayShape.cshtml @@ -25,22 +25,22 @@ - - The inner HTML of the <html-content name="propertyName"> tag helper (which is a direct child + + The inner HTML of the <add-property name="propertyName"> tag helper (which is a direct child of the <shape> tag helper) is converted into HTML and then passed to the shape as a model property. The property's name is the string passed into the name attribute. Even other shapes can be included! - - + + You can have multiple, they are just @nameof(IHtmlContent) type shape properties. - + - - If a <html-content> tag helper exists, it takes precedence over any matching attribute of the + + If a <add-property> tag helper exists, it takes precedence over any matching attribute of the <shape> tag helper. This is because child tag helpers are evaluated after the shape is created, right before it's displayed. - + diff --git a/src/OrchardCore/OrchardCore.DisplayManagement/TagHelpers/HtmlContentTagHelper.cs b/src/OrchardCore/OrchardCore.DisplayManagement/TagHelpers/HtmlContentTagHelper.cs index 2dbcd8c2a9a..320815715f1 100644 --- a/src/OrchardCore/OrchardCore.DisplayManagement/TagHelpers/HtmlContentTagHelper.cs +++ b/src/OrchardCore/OrchardCore.DisplayManagement/TagHelpers/HtmlContentTagHelper.cs @@ -4,11 +4,12 @@ namespace OrchardCore.DisplayManagement.TagHelpers; -[HtmlTargetElement("html-content", Attributes = "name", TagStructure = TagStructure.NormalOrSelfClosing)] +[HtmlTargetElement("add-property", Attributes = "name", TagStructure = TagStructure.NormalOrSelfClosing)] public class HtmlContentTagHelper : TagHelper { [HtmlAttributeName("name")] public string Name { get; set; } + public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) { var shape = (IShape)context.Items[typeof(IShape)]; From 4ac5a176ff533030dfa9699f2e5ba58e38c593ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A1ra=20El-Saig?= Date: Sun, 11 Feb 2024 02:10:51 +0100 Subject: [PATCH 18/32] Add optional value attribute to add-property. --- .../OrchardCore.Demo/Views/EmbedContentInShape.cshtml | 5 +++++ .../OrchardCore.Demo/Views/Home/DisplayShape.cshtml | 1 + .../TagHelpers/HtmlContentTagHelper.cs | 4 +++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Demo/Views/EmbedContentInShape.cshtml b/src/OrchardCore.Modules/OrchardCore.Demo/Views/EmbedContentInShape.cshtml index 398ffb112fc..4d414ebc735 100644 --- a/src/OrchardCore.Modules/OrchardCore.Demo/Views/EmbedContentInShape.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Demo/Views/EmbedContentInShape.cshtml @@ -5,6 +5,11 @@

@Model.HtmlContent

The content is inserted above this line.

+ @if (Model.SomeProperty != null) + { +

And here is another property: @Model.SomeProperty.

+ } + @if (Model.OtherContent is IHtmlContent otherContent) { diff --git a/src/OrchardCore.Modules/OrchardCore.Demo/Views/Home/DisplayShape.cshtml b/src/OrchardCore.Modules/OrchardCore.Demo/Views/Home/DisplayShape.cshtml index c26b6c7c21a..ccd964e5e80 100644 --- a/src/OrchardCore.Modules/OrchardCore.Demo/Views/Home/DisplayShape.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Demo/Views/Home/DisplayShape.cshtml @@ -35,6 +35,7 @@ You can have multiple, they are just @nameof(IHtmlContent) type shape properties. +
diff --git a/src/OrchardCore/OrchardCore.DisplayManagement/TagHelpers/HtmlContentTagHelper.cs b/src/OrchardCore/OrchardCore.DisplayManagement/TagHelpers/HtmlContentTagHelper.cs index 320815715f1..15909b21127 100644 --- a/src/OrchardCore/OrchardCore.DisplayManagement/TagHelpers/HtmlContentTagHelper.cs +++ b/src/OrchardCore/OrchardCore.DisplayManagement/TagHelpers/HtmlContentTagHelper.cs @@ -17,7 +17,9 @@ public override async Task ProcessAsync(TagHelperContext context, TagHelperOutpu if (!string.IsNullOrWhiteSpace(Name)) { var content = await output.GetChildContentAsync(useCachedResult: false); - shape.Properties[Name.Trim()] = new HtmlString(content.GetContent()); + shape.Properties[Name.Trim()] = output.Attributes.ContainsName("value") + ? output.Attributes["value"].Value + : new HtmlString(content.GetContent()); } output.SuppressOutput(); From 35f6e205f575039d4abe132440c3cca02c5aac80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A1ra=20El-Saig?= Date: Sun, 11 Feb 2024 03:07:35 +0100 Subject: [PATCH 19/32] rename file and class to AddPropertyTagHelper --- .../{HtmlContentTagHelper.cs => AddPropertyTagHelper.cs} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename src/OrchardCore/OrchardCore.DisplayManagement/TagHelpers/{HtmlContentTagHelper.cs => AddPropertyTagHelper.cs} (95%) diff --git a/src/OrchardCore/OrchardCore.DisplayManagement/TagHelpers/HtmlContentTagHelper.cs b/src/OrchardCore/OrchardCore.DisplayManagement/TagHelpers/AddPropertyTagHelper.cs similarity index 95% rename from src/OrchardCore/OrchardCore.DisplayManagement/TagHelpers/HtmlContentTagHelper.cs rename to src/OrchardCore/OrchardCore.DisplayManagement/TagHelpers/AddPropertyTagHelper.cs index 15909b21127..08394898614 100644 --- a/src/OrchardCore/OrchardCore.DisplayManagement/TagHelpers/HtmlContentTagHelper.cs +++ b/src/OrchardCore/OrchardCore.DisplayManagement/TagHelpers/AddPropertyTagHelper.cs @@ -5,7 +5,7 @@ namespace OrchardCore.DisplayManagement.TagHelpers; [HtmlTargetElement("add-property", Attributes = "name", TagStructure = TagStructure.NormalOrSelfClosing)] -public class HtmlContentTagHelper : TagHelper +public class AddPropertyTagHelper : TagHelper { [HtmlAttributeName("name")] public string Name { get; set; } From 339505717736753f0361eeb68bc6dee8996ad326 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A1ra=20El-Saig?= Date: Sun, 11 Feb 2024 21:39:22 +0100 Subject: [PATCH 20/32] Update documentation. --- src/docs/reference/core/Placement/README.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/docs/reference/core/Placement/README.md b/src/docs/reference/core/Placement/README.md index 8b43c7f1ee2..7cf0e8815ea 100644 --- a/src/docs/reference/core/Placement/README.md +++ b/src/docs/reference/core/Placement/README.md @@ -175,6 +175,26 @@ Metadata tag helper example: ``` +#### Adding properties with child tag helpers + +Properties can be passed to a shape by adding attributes to the shape tag helper, as mentioned above. But you can also use the `` tag helper inside ``. This even lets you pass Razor code as properties with `IHtmlContent` value, if you omit the `value` attribute. Something that can't be easily done otherwise. + +```razor + + + + +

Some complicated HTML

+
+ You can even include shapes: + +
+
+
+``` + +This is the same as `` where you'd have to construct `someHtmlContentVariable` separately. Of course you can mix and match the different formats, for example to only use `` when you want to pass HTML content as property. + ### Date Time shapes #### `DateTime` From fd29e62aed5c9a7bcdaa080b07ab4eaf0f7dc52b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A1ra=20El-Saig?= Date: Sun, 11 Feb 2024 21:47:52 +0100 Subject: [PATCH 21/32] wording --- src/docs/reference/core/Placement/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/docs/reference/core/Placement/README.md b/src/docs/reference/core/Placement/README.md index 7cf0e8815ea..174788755fb 100644 --- a/src/docs/reference/core/Placement/README.md +++ b/src/docs/reference/core/Placement/README.md @@ -175,7 +175,7 @@ Metadata tag helper example: ``` -#### Adding properties with child tag helpers +#### Adding properties with additional tag helpers Properties can be passed to a shape by adding attributes to the shape tag helper, as mentioned above. But you can also use the `` tag helper inside ``. This even lets you pass Razor code as properties with `IHtmlContent` value, if you omit the `value` attribute. Something that can't be easily done otherwise. From 1b40522c801ce4f25e31ae27c857881cb6b948a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A1ra=20El-Saig?= Date: Sun, 11 Feb 2024 21:55:44 +0100 Subject: [PATCH 22/32] Use prop- in explanation. --- src/docs/reference/core/Placement/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/docs/reference/core/Placement/README.md b/src/docs/reference/core/Placement/README.md index 174788755fb..ddf0e96f94e 100644 --- a/src/docs/reference/core/Placement/README.md +++ b/src/docs/reference/core/Placement/README.md @@ -193,7 +193,7 @@ Properties can be passed to a shape by adding attributes to the shape tag helper ``` -This is the same as `` where you'd have to construct `someHtmlContentVariable` separately. Of course you can mix and match the different formats, for example to only use `` when you want to pass HTML content as property. +This is the same as `` where you'd have to construct `someHtmlContentVariable` separately. Of course you can mix and match the different formats, for example to only use `` when you want to pass HTML content as property. ### Date Time shapes From e3840cfa0c37336d1221bf473c7283380f4e5813 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A1ra=20El-Saig?= Date: Mon, 17 Jun 2024 02:00:26 +0200 Subject: [PATCH 23/32] Update src/docs/reference/core/Placement/README.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Zoltán Lehóczky --- src/docs/reference/core/Placement/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/docs/reference/core/Placement/README.md b/src/docs/reference/core/Placement/README.md index 6a223f09944..f113c92999d 100644 --- a/src/docs/reference/core/Placement/README.md +++ b/src/docs/reference/core/Placement/README.md @@ -193,7 +193,7 @@ Properties can be passed to a shape by adding attributes to the shape tag helper ``` -This is the same as `` where you'd have to construct `someHtmlContentVariable` separately. Of course you can mix and match the different formats, for example to only use `` when you want to pass HTML content as property. +This is the same as `` where you'd have to construct `someHtmlContentVariable` separately. Of course, you can mix and match the different formats, for example, to only use `` when you want to pass HTML content as property. ### Date Time shapes From d5da5fb9155c06b0f8c0ee615301217b7ff116b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A1ra=20El-Saig?= Date: Mon, 17 Jun 2024 02:00:59 +0200 Subject: [PATCH 24/32] Update src/docs/reference/core/Placement/README.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Zoltán Lehóczky --- src/docs/reference/core/Placement/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/docs/reference/core/Placement/README.md b/src/docs/reference/core/Placement/README.md index f113c92999d..e452cfa00c5 100644 --- a/src/docs/reference/core/Placement/README.md +++ b/src/docs/reference/core/Placement/README.md @@ -179,7 +179,7 @@ Metadata tag helper example: Properties can be passed to a shape by adding attributes to the shape tag helper, as mentioned above. But you can also use the `` tag helper inside ``. This even lets you pass Razor code as properties with `IHtmlContent` value, if you omit the `value` attribute. Something that can't be easily done otherwise. -```razor +```xml From 2817473a1d8ec24aca9cbf87b1175459dd15d768 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A1ra=20El-Saig?= Date: Mon, 17 Jun 2024 02:21:39 +0200 Subject: [PATCH 25/32] Reference in change log. --- src/docs/releases/2.0.0.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/docs/releases/2.0.0.md b/src/docs/releases/2.0.0.md index a3eb6e9c31f..7d0aa153284 100644 --- a/src/docs/releases/2.0.0.md +++ b/src/docs/releases/2.0.0.md @@ -593,4 +593,8 @@ A new filter named `supported_cultures` was added to allow you to get a list of ### Sealing Types -Many configuration classes commonly used by modules can be `sealed`, which improves runtime performance. We've implemented this enhancement in [this pull request](https://github.com/OrchardCMS/OrchardCore/pull/16253) and [this one](https://github.com/OrchardCMS/OrchardCore/pull/16238). While it's not mandatory, we recommend that you consider applying this improvement to your own extensions as well. \ No newline at end of file +Many configuration classes commonly used by modules can be `sealed`, which improves runtime performance. We've implemented this enhancement in [this pull request](https://github.com/OrchardCMS/OrchardCore/pull/16253) and [this one](https://github.com/OrchardCMS/OrchardCore/pull/16238). While it's not mandatory, we recommend that you consider applying this improvement to your own extensions as well. + +### Adding properties with additional tag helpers + +The new `` tag helper can be placed inside `` tag helpers to add properties to the shape. This is similar to `prop-*` attributes, but you can also include Razor code as `IHtmlContent` property value, which was not possible before. See more details [here](../reference/core/Placement/README.md#adding-properties-with-additional-tag-helpers). From f3a1d011e64182b551b8b7c3c3001f642e289123 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A1ra=20El-Saig?= Date: Mon, 17 Jun 2024 02:27:35 +0200 Subject: [PATCH 26/32] Move demo code to separate action. --- .../Controllers/HomeController.cs | 2 ++ .../Views/Home/AddProperty.cshtml | 23 +++++++++++++++++++ .../Views/Home/DisplayShape.cshtml | 23 ------------------- 3 files changed, 25 insertions(+), 23 deletions(-) create mode 100644 src/OrchardCore.Modules/OrchardCore.Demo/Views/Home/AddProperty.cshtml diff --git a/src/OrchardCore.Modules/OrchardCore.Demo/Controllers/HomeController.cs b/src/OrchardCore.Modules/OrchardCore.Demo/Controllers/HomeController.cs index 9397b42f618..69ce76ff4b4 100644 --- a/src/OrchardCore.Modules/OrchardCore.Demo/Controllers/HomeController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Demo/Controllers/HomeController.cs @@ -109,6 +109,8 @@ public async Task DisplayShape(string contentItemId) return View(shape); } + public IActionResult AddProperty() => View(); + public ActionResult Raw() { return View(); diff --git a/src/OrchardCore.Modules/OrchardCore.Demo/Views/Home/AddProperty.cshtml b/src/OrchardCore.Modules/OrchardCore.Demo/Views/Home/AddProperty.cshtml new file mode 100644 index 00000000000..963b7140ab5 --- /dev/null +++ b/src/OrchardCore.Modules/OrchardCore.Demo/Views/Home/AddProperty.cshtml @@ -0,0 +1,23 @@ +@using Microsoft.AspNetCore.Html + + + + The inner HTML of the <add-property name="propertyName"> tag helper (which is a direct child + of the <shape> tag helper) is converted into HTML and then passed to the shape as a model + property. The property's name is the string passed into the name attribute. + + Even other shapes can be included! + + + You can have multiple, they are just @nameof(IHtmlContent) type shape properties. + + + + + + + If a <add-property> tag helper exists, it takes precedence over any matching attribute of the + <shape> tag helper. This is because child tag helpers are evaluated after the shape is + created, right before it's displayed. + + \ No newline at end of file diff --git a/src/OrchardCore.Modules/OrchardCore.Demo/Views/Home/DisplayShape.cshtml b/src/OrchardCore.Modules/OrchardCore.Demo/Views/Home/DisplayShape.cshtml index 91022342761..3ec26e02c9c 100644 --- a/src/OrchardCore.Modules/OrchardCore.Demo/Views/Home/DisplayShape.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Demo/Views/Home/DisplayShape.cshtml @@ -1,4 +1,3 @@ -@using Microsoft.AspNetCore.Html @model dynamic @addTagHelper "*, OrchardCore.Resources" @addTagHelper "*, OrchardCore.Demo" @@ -23,25 +22,3 @@ - - - - The inner HTML of the <add-property name="propertyName"> tag helper (which is a direct child - of the <shape> tag helper) is converted into HTML and then passed to the shape as a model - property. The property's name is the string passed into the name attribute. - - Even other shapes can be included! - - - You can have multiple, they are just @nameof(IHtmlContent) type shape properties. - - - - - - - If a <add-property> tag helper exists, it takes precedence over any matching attribute of the - <shape> tag helper. This is because child tag helpers are evaluated after the shape is - created, right before it's displayed. - - From 8d6b12d4a8e3b5ea106c991a655738769d8fac6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A1ra=20El-Saig?= Date: Mon, 17 Jun 2024 02:28:28 +0200 Subject: [PATCH 27/32] fix spacing --- .../OrchardCore.Demo/Views/Home/AddProperty.cshtml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Demo/Views/Home/AddProperty.cshtml b/src/OrchardCore.Modules/OrchardCore.Demo/Views/Home/AddProperty.cshtml index 963b7140ab5..58a71d9f4b2 100644 --- a/src/OrchardCore.Modules/OrchardCore.Demo/Views/Home/AddProperty.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Demo/Views/Home/AddProperty.cshtml @@ -20,4 +20,4 @@ <shape> tag helper. This is because child tag helpers are evaluated after the shape is created, right before it's displayed. - \ No newline at end of file + From 499b08ab4e188b183dd2c07eb104a79a035cf07e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A1ra=20El-Saig?= Date: Mon, 17 Jun 2024 11:31:58 +0200 Subject: [PATCH 28/32] Update src/docs/releases/2.0.0.md Co-authored-by: Hisham Bin Ateya --- src/docs/releases/2.0.0.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/docs/releases/2.0.0.md b/src/docs/releases/2.0.0.md index 7d0aa153284..ebe54233e93 100644 --- a/src/docs/releases/2.0.0.md +++ b/src/docs/releases/2.0.0.md @@ -597,4 +597,4 @@ Many configuration classes commonly used by modules can be `sealed`, which impro ### Adding properties with additional tag helpers -The new `` tag helper can be placed inside `` tag helpers to add properties to the shape. This is similar to `prop-*` attributes, but you can also include Razor code as `IHtmlContent` property value, which was not possible before. See more details [here](../reference/core/Placement/README.md#adding-properties-with-additional-tag-helpers). +The new `` tag helper can be placed inside the `` tag helpers to add properties to the shape. This is similar to `prop-*` attributes, but you can also include Razor code as the `IHtmlContent` property value, which was impossible before. See more details [here](../reference/core/Placement/README.md#adding-properties-with-additional-tag-helpers). From 4d06f62065f7d4f191c36467e285c67f2bd12957 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A1ra=20El-Saig?= Date: Mon, 17 Jun 2024 11:32:08 +0200 Subject: [PATCH 29/32] Update src/OrchardCore.Modules/OrchardCore.Demo/Views/EmbedContentInShape.cshtml Co-authored-by: Hisham Bin Ateya --- .../OrchardCore.Demo/Views/EmbedContentInShape.cshtml | 1 - 1 file changed, 1 deletion(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Demo/Views/EmbedContentInShape.cshtml b/src/OrchardCore.Modules/OrchardCore.Demo/Views/EmbedContentInShape.cshtml index 4d414ebc735..f054a9d781d 100644 --- a/src/OrchardCore.Modules/OrchardCore.Demo/Views/EmbedContentInShape.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Demo/Views/EmbedContentInShape.cshtml @@ -12,7 +12,6 @@ @if (Model.OtherContent is IHtmlContent otherContent) { -

Another property called "OtherContent" starts here.

@otherContent

From f223a9ed5ed575291142a7fd8ffdc6a1489213f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A1ra=20El-Saig?= Date: Mon, 17 Jun 2024 11:32:48 +0200 Subject: [PATCH 30/32] Update src/docs/reference/core/Placement/README.md Co-authored-by: Hisham Bin Ateya --- src/docs/reference/core/Placement/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/docs/reference/core/Placement/README.md b/src/docs/reference/core/Placement/README.md index e452cfa00c5..f5c416bf1e2 100644 --- a/src/docs/reference/core/Placement/README.md +++ b/src/docs/reference/core/Placement/README.md @@ -177,7 +177,7 @@ Metadata tag helper example: #### Adding properties with additional tag helpers -Properties can be passed to a shape by adding attributes to the shape tag helper, as mentioned above. But you can also use the `` tag helper inside ``. This even lets you pass Razor code as properties with `IHtmlContent` value, if you omit the `value` attribute. Something that can't be easily done otherwise. +Properties can be passed to a shape by adding attributes to the shape tag helper, as mentioned above. But you can also use the `` tag helper inside ``. This even lets you pass Razor code as properties with the `IHtmlContent` value, if you omit the `value` attribute. Something that can't be easily done otherwise. ```xml From 331c8f6c3a5904fccdc0f9a6e6e81e52764e2ca5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A1ra=20El-Saig?= Date: Mon, 17 Jun 2024 12:34:25 +0200 Subject: [PATCH 31/32] Update src/OrchardCore/OrchardCore.DisplayManagement/TagHelpers/AddPropertyTagHelper.cs Co-authored-by: Hisham Bin Ateya --- .../TagHelpers/AddPropertyTagHelper.cs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/OrchardCore/OrchardCore.DisplayManagement/TagHelpers/AddPropertyTagHelper.cs b/src/OrchardCore/OrchardCore.DisplayManagement/TagHelpers/AddPropertyTagHelper.cs index 08394898614..1af4565a368 100644 --- a/src/OrchardCore/OrchardCore.DisplayManagement/TagHelpers/AddPropertyTagHelper.cs +++ b/src/OrchardCore/OrchardCore.DisplayManagement/TagHelpers/AddPropertyTagHelper.cs @@ -12,16 +12,17 @@ public class AddPropertyTagHelper : TagHelper public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) { - var shape = (IShape)context.Items[typeof(IShape)]; - - if (!string.IsNullOrWhiteSpace(Name)) + if (string.IsNullOrWhiteSpace(Name)) { - var content = await output.GetChildContentAsync(useCachedResult: false); - shape.Properties[Name.Trim()] = output.Attributes.ContainsName("value") - ? output.Attributes["value"].Value - : new HtmlString(content.GetContent()); + return; } + var content = await output.GetChildContentAsync(useCachedResult: false); + var shape = (IShape)context.Items[typeof(IShape)]; + shape.Properties[Name.Trim()] = output.Attributes.ContainsName("value") + ? output.Attributes["value"].Value + : new HtmlString(content.GetContent()); + output.SuppressOutput(); } } From eb28a0f63e02b657ea3bcd057d865cdab1679063 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A1ra=20El-Saig?= Date: Mon, 17 Jun 2024 13:09:39 +0200 Subject: [PATCH 32/32] Update src/docs/releases/2.0.0.md Co-authored-by: Hisham Bin Ateya --- src/docs/releases/2.0.0.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/docs/releases/2.0.0.md b/src/docs/releases/2.0.0.md index ebe54233e93..606d9c0d122 100644 --- a/src/docs/releases/2.0.0.md +++ b/src/docs/releases/2.0.0.md @@ -593,7 +593,7 @@ A new filter named `supported_cultures` was added to allow you to get a list of ### Sealing Types -Many configuration classes commonly used by modules can be `sealed`, which improves runtime performance. We've implemented this enhancement in [this pull request](https://github.com/OrchardCMS/OrchardCore/pull/16253) and [this one](https://github.com/OrchardCMS/OrchardCore/pull/16238). While it's not mandatory, we recommend that you consider applying this improvement to your own extensions as well. +Many configuration classes commonly used by modules can be `sealed`, which improves runtime performance. We've implemented this enhancement in [this pull request](https://github.com/OrchardCMS/OrchardCore/pull/16253) and [this one](https://github.com/OrchardCMS/OrchardCore/pull/16238). While it's not mandatory, we recommend that you consider applying this improvement to your extensions as well. ### Adding properties with additional tag helpers