I'm attempting to make a multi-value Component link inline editable using DD4T2's XpmExtension
methods to render the XPM markup. I'm using SDL Web 8.5.
Setup:
I have a Component List Schema with the following fields:
The linked Component fields are as follows:
First Approach
This is a simplified view to render the Component list:
<div class="gridspan24">
@if (XpmExtensions.XpmMarkupService.IsSiteEditEnabled())
{
@Model.StartXpmEditingZone()
}
<section class="listblocks">
<h2>@Model.XpmEditableField(x => x.Title)</h2>
@if (XpmExtensions.XpmMarkupService.IsSiteEditEnabled())
{
if (Model.BodyText != null)
{
@Model.XpmEditableField(x => m.BodyText)
}
}
else
{
@Model.BodyText
}
@if (Model.Components != null && Model.Components.Any())
{
foreach (var component in Model.Components)
{
// Partial view for linked component list
}
}
</section>
</div>
This renders:
<div class="gridspan24">
<!-- Start Component Presentation: {"ComponentID" : "tcm:18-615", "ComponentModified" : "2017-06-21T10:31:57", "ComponentTemplateID" : "tcm:18-601-32", "ComponentTemplateModified" : "2017-06-22T05:22:25", "IsRepositoryPublished" : false} -->
<section class="listblocks">
<h2><!-- Start Component Field: {"XPath":"tcm:Content/custom:component_list/custom:title"} -->Full List Block</h2>
<!-- Start Component Field: {"XPath":"tcm:Content/custom:component_list/custom:body_text"} --><p>Test</p>
<article class="listblock__item">
<img class="listblock__img" alt="" src="" srcset="">
<div class="listblock__content">
<h3><!-- Start Component Field: {"XPath":"tcm:Content/custom:general_content/custom:title"} -->List Block - Component A</h3>
<div class="listblock__copy">
<!-- Start Component Field: {"XPath":"tcm:Content/custom:general_content/custom:body_text"} --><p>Test</p>
</div>
<div class="listblock__ctas">
<p class="listblock__cta">
<a href="" class="">Notice Block<span class="visuallyhidden"> Hidden Text </span></a>
</p>
<p class="listblock__cta">
<a href="" class="">Internal Link Text<span class="visuallyhidden"> Internal Link Summary </span></a>
</p>
</div>
</div>
</article>
// Other linked components
</section>
</div>
It was made clear to me that XPM won't have the context of the inner linked Components to know the difference. The result is that when editing the content and updating the Component list's body text, it would clear the linked Component's body text too.
Second Approach
I followed the given example and read the reference:
This suggested that for each Component to be rendered in the Component list, I have to render the Start Component Presentation
XPM markup inside the <article>
element.
The following markup was hard-coded for testing purposes:
<div class="gridspan24">
<!-- Start Component Presentation: {"ID": "cp_1", "ComponentID" : "tcm:18-618", "ComponentModified" : "2017-06-22T09:09:31", "ComponentTemplateID" : "tcm:14-600-32", "ComponentTemplateModified" : "2017-06-22T07:30:20", "IsRepositoryPublished" : false} -->
<article class="listblock__item">
<div class="listblock__content">
<div class="listblock__copy">
<!-- Start Component Field: {"ID": "cp_1", "XPath":"tcm:Content/custom:component_list/custom:body_text"} -->
<p>Test</p>
</div>
<div class="listblock__ctas">
<p class="listblock__cta">
<a href="http://www.google.co.uk/" class="" aria-describedby="extdisclaimer">Google<span class="visuallyhidden"> </span></a>
</p>
</div>
</div>
</article>
<article class="listblock__item">
<!-- Start Component Presentation: {"ID": "cp_2", "ComponentID": "tcm:13-617", "ComponentTemplateID": "tcm:14-600-32"}-->
<img class="listblock__img" alt="" src="" srcset="">
<div class="listblock__content">
<h3><!-- Start Component Field: {"ID": "cp_2", "XPath":"tcm:Content/custom:component_list/custom:components[0]/custom:general_content/custom:title"} -->List Block - Component A</h3>
<div class="listblock__copy">
<!-- Start Component Field: {"ID": "cp_2", "XPath":"tcm:Content/custom:component_list/custom:components[0]/custom:general_content/custom:body_text"} -->
<p>Test</p>
</div>
<div class="listblock__ctas">
<p class="listblock__cta">
<a href="" class="">Notice Block<span class="visuallyhidden"> Hidden Text </span></a>
</p>
<p class="listblock__cta">
<a href="" class="">Internal Link Text<span class="visuallyhidden"> Internal Link Summary </span></a>
</p>
</div>
</div>
</article>
</div>
This resolved clearing the linked Component when I'm editing the title body text of my Component list but this is not allowing me to edit the linked Component.
Update:
I've also had a look at Nuno's answer here but I'm unable to find an IsDynamic
attribute in the documentation.
Summary:
Is there something I'm missing with how my XPM markup has been rendered or how the HTML has been structured?