|
Final comments from observations after using this a while. The code above presents one problem, it hides content items that would appear twice. This is problematic when you have a widget that projects the same content items as another projection on the page
(as they will be filtered out). My last bit of comfort in getting a working solution is to just limit the number of levels for which Projections reveals nested projections for - here is the code for that:
At the top of the file (outside any methods) - of course, you can change your "MaximumLevel" to however many nested levels you want:
// EMS CHANGE - start
protected List<ContentItem> ProcessedContentItems = new List<ContentItem>();
int CurrentLevel = 0;
const int MaximumLevel = 1;
// EMS CHANGE - end
At the start of "Display"):
// EMS CHANGE - start
if (CurrentLevel >= MaximumLevel) {
return null;
}
// EMS CHANGE - end
Inside the ContentShape area:
// EMS CHANGE - start
CurrentLevel++;
try {
// ORIGINAL CODE
// sanity check so that content items with ProjectionPart can't be added here, or it will result in an infinite loop
//contentItems = contentItems.Where(x => !x.Has<ProjectionPart>()).ToList();
// EMS CHANGE - end
Note that I have the try { so at the bottom of the ContentShape area I have the finally (to ensure the CurrentLevel is reduced):
// EMS CHAGE - start
}
finally {
CurrentLevel--;
}
// EMS CHANGE - end
And that does it, no more removing content items, just limiting the number of nested projections that can appear. This would go nicely into a Projections Setting (though I have not coded it yet).
|