Widget code-behind for single item templates

Posted by Community Admin on 04-Aug-2018 15:49

Widget code-behind for single item templates

All Replies

Posted by Community Admin on 27-Mar-2014 00:00

Hi,

I've been using the following to add code-behind to built in widgets for list items which works great 

www.sitefinity.com/.../howto-guide-add-code-behind-to-a-sitefinity-widget-template

I'd like to do the same for single items, does anyone know how I can access the data items in the code-behind? 

Posted by Community Admin on 01-Apr-2014 00:00

Hi David,

The procedure would be similar for a single item, but in this case you will work on the Full Blog Post item template by going to Design>>Widget  Templates.

Another easy way to get the current item would consist on extending the Blog Posts widget (or creating a new one). It is easily possible by creating a class which inherits from BlogPostView in Visual Studio as shown on this video.

The code may look similar to this:

public class CustomBlogPostItem : BlogPostView
    
        protected override void CreateChildControls()
        
            base.CreateChildControls();
            var view = this.CurrentView;
            if (view.ViewType.FullName == "Telerik.Sitefinity.Modules.Blogs.Web.UI.Public.DetailPostView")
            
                var item = this.DetailItem;
 
 
            
 
        
    



Kind Regards,
Junior Dominguez
Telerik
 
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 Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
 

This thread is closed