Skip to content

Commit

Permalink
Fixed issue rendering nested empty placeholders
Browse files Browse the repository at this point in the history
  • Loading branch information
robearlam committed Aug 6, 2024
1 parent b6387b9 commit 2b9f5a5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public override async Task ProcessAsync(TagHelperContext context, TagHelperOutpu

if (!foundPlaceholderFeatures)
{
output.Content.SetHtmlContent($"<!-- {string.Format(Resources.Warning_PlaceholderWasEmpty, placeholderName)} -->");
output.Content.SetHtmlContent($"<div className=\"sc-jss-empty-placeholder\"></div>");
}
}

Expand All @@ -109,14 +109,12 @@ public override async Task ProcessAsync(TagHelperContext context, TagHelperOutpu
Placeholder? placeholderFeatures = null;

// try to get the placeholder from the "context" component
renderingContext.Component?.Placeholders.TryGetValue(placeholderName, out placeholderFeatures);

// top level placeholders do not have a "context" component set, so their component list can be retrieved directly from the Sitecore Route object
if (placeholderFeatures?.Count > 0)
if (renderingContext.Component?.Placeholders.TryGetValue(placeholderName, out placeholderFeatures) ?? false)
{
return placeholderFeatures;
}

// top level placeholders do not have a "context" component set, so their component list can be retrieved directly from the Sitecore Route object
Route? route = renderingContext.Response?.Content?.Sitecore?.Route;
route?.Placeholders.TryGetValue(placeholderName, out placeholderFeatures);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ public async Task ProcessAsync_PlaceholderNameInLayoutServiceResponseAndPlacehol
await sut.ProcessAsync(tagHelperContext, tagHelperOutput);

// Assert
tagHelperOutput.Content.GetContent().Should().Be($"<!-- Placeholder '{PlaceHolderWithNoComponentsName}' was empty. -->");
tagHelperOutput.Content.GetContent().Should().Be($"<div className=\"sc-jss-empty-placeholder\"></div>");
}

[Theory]
Expand Down

0 comments on commit 2b9f5a5

Please sign in to comment.