diff --git a/src/Sitecore.AspNetCore.SDK.RenderingEngine/TagHelpers/PlaceholderTagHelper.cs b/src/Sitecore.AspNetCore.SDK.RenderingEngine/TagHelpers/PlaceholderTagHelper.cs
index c42ef29..a83d6cb 100644
--- a/src/Sitecore.AspNetCore.SDK.RenderingEngine/TagHelpers/PlaceholderTagHelper.cs
+++ b/src/Sitecore.AspNetCore.SDK.RenderingEngine/TagHelpers/PlaceholderTagHelper.cs
@@ -70,8 +70,13 @@ public override async Task ProcessAsync(TagHelperContext context, TagHelperOutpu
return;
}
- bool foundPlaceholderFeatures = false;
+ bool emptyEdit = IsInEditingMode(renderingContext) && IsPlaceHolderEmpty(placeholderFeatures);
+ if (emptyEdit)
+ {
+ output.Content.AppendHtml("
");
+ }
+ bool foundPlaceholderFeatures = false;
foreach (IPlaceholderFeature placeholderFeature in placeholderFeatures.OfType())
{
foundPlaceholderFeatures = true;
@@ -98,12 +103,27 @@ public override async Task ProcessAsync(TagHelperContext context, TagHelperOutpu
output.Content.AppendHtml(html);
}
+ if (emptyEdit)
+ {
+ output.Content.AppendHtml("
");
+ }
+
if (!foundPlaceholderFeatures)
{
output.Content.SetHtmlContent($"");
}
}
+ private static bool IsInEditingMode(ISitecoreRenderingContext renderingContext)
+ {
+ return renderingContext.Response?.Content?.Sitecore?.Context?.IsEditing ?? false;
+ }
+
+ private static bool IsPlaceHolderEmpty(Placeholder placeholderFeatures)
+ {
+ return !placeholderFeatures.Exists(x => x is Component);
+ }
+
private static Placeholder? GetPlaceholderFeatures(string placeholderName, ISitecoreRenderingContext renderingContext)
{
Placeholder? placeholderFeatures = null;
diff --git a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Tests/TagHelpers/PlaceholderTagHelperFixture.cs b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Tests/TagHelpers/PlaceholderTagHelperFixture.cs
index ce58090..6794636 100644
--- a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Tests/TagHelpers/PlaceholderTagHelperFixture.cs
+++ b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Tests/TagHelpers/PlaceholderTagHelperFixture.cs
@@ -476,6 +476,53 @@ public async Task ProcessAsync_PlaceholderContainsUnknownPlaceholderFeature_Outp
tagHelperOutput.Content.GetContent().Should().BeEmpty();
}
+ [Theory]
+ [AutoNSubstituteData]
+ public async Task ProcessAsync_PlaceholderContainsUnknownPlaceholderFeature_IsInEditingMode_OutputIsEditingWrapperTag(
+ PlaceholderTagHelper sut,
+ ViewContext viewContext,
+ TagHelperContext tagHelperContext,
+ TagHelperOutput tagHelperOutput)
+ {
+ // Arrange
+ SitecoreRenderingContext context = new()
+ {
+ Response = new SitecoreLayoutResponse([])
+ {
+ Content = new SitecoreLayoutResponseContent
+ {
+ Sitecore = new SitecoreData
+ {
+ Context = new Context { IsEditing = true },
+ Route = new Route
+ {
+ Placeholders =
+ {
+ [PlaceHolderWithComponentsName] =
+ [
+ new TestPlaceholderFeature
+ {
+ Content = TestComponentRenderer.HtmlContent
+ }
+ ]
+ }
+ }
+ }
+ }
+ }
+ };
+
+ viewContext.HttpContext.SetSitecoreRenderingContext(context);
+ sut.Name = PlaceHolderWithComponentsName;
+ sut.ViewContext = viewContext;
+
+ // Act
+ await sut.ProcessAsync(tagHelperContext, tagHelperOutput);
+
+ // Assert
+ tagHelperOutput.Content.GetContent().Should().Be("");
+ }
+
[Theory]
[AutoNSubstituteData]
public async Task ProcessAsync_PlaceholderNameInLayoutServiceResponseAndPlaceholderIsNotEmpty_ContextComponentDoNotChange(