I'm using dynamic placeholders in the views, and there are nested views.
When giving the placeholder path for a rendering (in Presentation > Details),
the path should be - main-placeholder/sub-placeholder. But it doesn't render anything in that way. When given only the sub-placeholder, it works.
Using Sitecore 8.2 MVC
Here are my class and views:
HTMLHelperExtensions.cs:
public static class HTMLHelperExtensions
{
public static HtmlString DynamicPlaceholder(this SitecoreHelper mySCHelper, string placeholderName)
{
string dynamicKey = GetDynamicKey(placeholderName);
if (!string.IsNullOrWhiteSpace(dynamicKey))
placeholderName = dynamicKey;
IDisposable disposable = PlaceholderContext.Enter(new PlaceholderContext(placeholderName));
return mySCHelper.Placeholder(placeholderName);
}
private static string GetDynamicKey(string placeHolderName)
{
bool needIncrement = false;
int incrementStep = 0;
IEnumerable<PlaceholderContext> myPlaceholders = ContextService.Get().GetInstances<PlaceholderContext>();
foreach (PlaceholderContext myPHContext in myPlaceholders)
{
if (myPHContext.PlaceholderName == placeHolderName || myPHContext.PlaceholderName.StartsWith(placeHolderName + "_"))
{
needIncrement = true;
incrementStep++;
}
}
if (needIncrement)
placeHolderName += "_" + incrementStep.ToString();
return placeHolderName;
}
}
default.cshtml
<body>
@Html.Sitecore.Placeholder("page-content")
</body>
Section Centered.cshtml
<section>
<div class="container">
@Html.Sitecore().DynamicPlaceholder("section-centered")
</div>
</section>
2 Column 6-6.cshtml
//this should come inside "section-centered"
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-6">
@Html.Sitecore().DynamicPlaceholder("col-wide-1")
</div>
<div class="col-lg-6 col-md-6 col-sm-6">
@Html.Sitecore().DynamicPlaceholder("col-wide-2")
</div>
</div>
The content is rendered, when I give the placeholders as this:
When I give the placeholders like this:
it only renders...
<section>
<div class="container">
::before
::after
</div>
</section>
As you see, the Article
is not rendered. I would like to give the nested paths as it would make sense. Where am i going wrong.
PlaceholderContext
.DynamicPlaceholders
all have unique IDs?