I am new to Umbraco and Articulate.
I was implementing logic for related posts based on current post. For this I am iterating through the blog posts -
Model.Parent.Children.Where(c => ...) and apply some conditions to pick related articles.
I am accessing various properties like categories, tags using code -
c.GetPropertyValue<string>("categories") and c.GetPropertyValue<string>("tags"). The above code returns correct values.
However, I am not sure whether I am querying it in the correct way since I am accessing every value using GetPropertyValue(). Ain't it possible to convert to specific type and access the properties directly. Here is a quick view from Quick Watch window in Visual Studio.
I could see types - ArticulateMarkdown and ArticulateRichText which are document types and not a class inside Articulate assembly (correct me if I'm wrong).
How can I do correct casting and access the properties like ArticulateMarkdown.Catgories and ArticulateRichText.Tags?
Looks like my question itself was confusing. Here is what is my doubt in very high level.
I knew that I can access property values using c.GetPropertyValue<string>("aliasName"). Instead of querying this everytime is it possible for me to cast it to it's specific type? For example do casting like c as ArticulateRichText so that I can work with the properties directly instead of querying using GetPropertyValue<T>.
Phew! Finally figured out the solution. We can pass IPublishedContent as constructor overload to Articulate models. For example, if we want to convert a blog post of type IPublishedContent to PostModel, we can use code snippet - var post = new PostModel(ipubContentObject);
Best way to access properties of blog post
Hello,
I am new to Umbraco and Articulate. I was implementing logic for related posts based on current post. For this I am iterating through the blog posts -
Model.Parent.Children.Where(c => ...)
and apply some conditions to pick related articles. I am accessing various properties like categories, tags using code -c.GetPropertyValue<string>("categories")
andc.GetPropertyValue<string>("tags")
. The above code returns correct values.However, I am not sure whether I am querying it in the correct way since I am accessing every value using
GetPropertyValue()
. Ain't it possible to convert to specific type and access the properties directly. Here is a quick view from Quick Watch window in Visual Studio.I could see types -
ArticulateMarkdown
andArticulateRichText
which are document types and not a class inside Articulate assembly (correct me if I'm wrong).How can I do correct casting and access the properties like
ArticulateMarkdown.Catgories
andArticulateRichText.Tags
?Any guidance will be appreciated.
Thanks.
Looks like my question itself was confusing. Here is what is my doubt in very high level.
I knew that I can access property values using
c.GetPropertyValue<string>("aliasName")
. Instead of querying this everytime is it possible for me to cast it to it's specific type? For example do casting likec as ArticulateRichText
so that I can work with the properties directly instead of querying usingGetPropertyValue<T>
.Hope this make it more sense. Thanks.
Phew! Finally figured out the solution. We can pass
IPublishedContent
as constructor overload to Articulate models. For example, if we want to convert a blog post of typeIPublishedContent
toPostModel
, we can use code snippet -var post = new PostModel(ipubContentObject);
Thanks.
is working on a reply...