Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Does anybody have a convenient way of using the content service API to update content that resides in a NestedContent property?
For example, say that a “Widget” doctype has been used to content load 100 pages in the website via NestedContent, how would you go about programmatically identifying the pages that use this Widget doctype in the NestedContent property so that you could then update a value within the Widget?
The ContentService GetContentOfContentType doesn’t do this.
You need to generate the JSON blob required by Nested Content yourself. It should be an array of objects, and each object must have the properties key, ncContentTypeAlias, and the properties of your desired document type.
I have previously done like this
var contentItem = ContentService.GetById(1);
var nestedContentValue = new JArray();
// you can add a loop here, if you need multiple nested items
var nestedContentItem = new JObject();
// you need to add a Guid as a key to your item
nestedContentItem .Add("key", Guid.NewGuid().ToString());
// and the desired doctype
// add the values for each property of your doctype
nestedContentItem.Add("myPropertyAlias", "some property value");
// finally, add you nestedContentItem, to your nestedContentValue
// then set the value of your IContent contentItem
Hope it helps :)
thanks Søren :D
i was just as interested to know how i should identify pages that contain the said doctype in their NestedContent property (your first line of code). Does anyone know convenient/efficient ways of doing that? thank you
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted