Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Abilash Ashok 63 posts 418 karma points
    Mar 06, 2017 @ 13:00
    Abilash Ashok
    0

    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") 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.

    vs-quick-watch

    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?

    Any guidance will be appreciated.

    Thanks.

  • Abilash Ashok 63 posts 418 karma points
    Mar 08, 2017 @ 12:24
    Abilash Ashok
    0

    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>.

    Hope this make it more sense. Thanks.

  • Abilash Ashok 63 posts 418 karma points
    Mar 14, 2017 @ 11:21
    Abilash Ashok
    100

    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);

    Thanks.

Please Sign in or register to post replies

Write your reply to:

Draft