Umbraco.BlockList > Getting value in C# (without ModelsBuilder)
Hello,
I am playing with the new Block List editor.
Rather than using Models Builder, I would like to grab the value using the old fashioned GetValue<T> approach from the IContent.
If I look at the stored value, I can see some JSON coming back, but I was under the assumption that somewhere in the pipeline a value converter would kick in, and I'd be able to cast to something useful?
Perhaps I've used Models Builders for too long, and I'm missing something?
public class Page
{
public Page(IContent content)
{
this.Title = content.GetValue<string>("title");
// (behind the scenes this is a big blob of JSON)
// when cast, returns null.
this.BodyBlocks = content.GetValue<BlockListModel>("bodyBlocks");
}
public string Title { get; }
public IEnumerable<BlockListItem> BodyBlocks { get; }
}
Figured out, the property value converters are not run on IContent only IPublishedContent. However, as I am working within the content publishing pipeline, I don't have IPublishedContent yet.
Can't see an immediate solution to that, so I am using JsonConvert to grab the data I require.
public class Page
{
public Page(IContent content)
{
this.Title = content.GetValue<string>("title");
var json = content.GetValue("bodyBlocks").ToString();
var bodyBlocks = JsonConvert.DeserializeObject<BlockEditorPropertyValue>(json);
this.BodyBlocks = bodyBlocks.ContentData;
}
public string Title { get; }
public List<object> BodyBlocks { get; }
}
public class BlockEditorPropertyValue
{
public object Layout { get; set; }
public List<object> ContentData { get; set; }
public object SettingsData { get; set; }
}
Umbraco.BlockList > Getting value in C# (without ModelsBuilder)
Hello,
I am playing with the new Block List editor.
Rather than using Models Builder, I would like to grab the value using the old fashioned
GetValue<T>
approach from theIContent
.If I look at the stored value, I can see some JSON coming back, but I was under the assumption that somewhere in the pipeline a value converter would kick in, and I'd be able to cast to something useful?
Perhaps I've used Models Builders for too long, and I'm missing something?
Figured out, the property value converters are not run on
IContent
onlyIPublishedContent
. However, as I am working within the content publishing pipeline, I don't have IPublishedContent yet.Can't see an immediate solution to that, so I am using JsonConvert to grab the data I require.
is working on a reply...