More in this section

Forums / Developing with Sitefinity / How to programmatically access label for custom field in blog

How to programmatically access label for custom field in blog

2 posts, 0 answered
  1. Mark
    Mark avatar
    22 posts
    16 Sep 2012
    16 Mar 2012
    Link to this post

    Using the native API, I am able to retrieve values from custom fields in a blog post using
    DataExtensions.GetValue(dataItem, fieldName).  My question is, how can I get the associated label for this fieldname?  For example, In a blog post, I have a custom field named "question1".  The label for question1 is "Name an animal with 4 legs".   So using the GetValue extension method, I can get the value for this question, but how do I programmatically get the "Name an animal with 4 legs" part of question1?  Please advise using native API syntax.

    Here's some simplified example code:
    1.BlogsManager blogsManager = BlogsManager.GetManager();
    2.// get all published blogs items
    3.var allBlogs = blogsManager.GetBlogPosts().Where(b => b.Status == ContentLifecycleStatus.Live).ToList();
    4.(string)DataExtensions.GetValue(allBlogs, "question1");

    Thank you.

  2. Boyan Barnev
    Boyan Barnev avatar
    1429 posts
    28 Aug 2017
    21 Mar 2012
    Link to this post
    Hello Mark,

    Can you please share with us the widget template you are currenlty using for your blog posts widget so we can give you a more specific advice? Please note that by adding the custom field on your template this will display just the value of the field, can you please make sure you have not added the label separately?

    Boyan Barnev
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
2 posts, 0 answered