More in this section

Forums / Developing with Sitefinity / Preview template GetContent of current item

Preview template GetContent of current item

4 posts, 0 answered
  1. Pierre
    Pierre avatar
    433 posts
    Registered:
    16 Feb 2006
    08 May 2009
    Link to this post
    Hi,

    I need to change the repeater of preview template with some view of current content. How to get the elements added in the Edit/InserMode in this template. How to get the Content.ID of current item from codebehind.

    Thanks. 
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    08 May 2009
    Link to this post
    Hello Pierre,

    repeaterItemMetaData control is required control. You can try changing the repeater by creating a custom view and setting the control as not required.

    Sample code:

    As you see you should inherit from ContentItemPreview and specify your Thost

    public class MyView : Telerik.Cms.Engine.WebControls.Admin.ContentItemPreview<NewsItemPreview> 
     
        protected override Repeater ItemMetaData 
        { 
            get 
            { 
                // set the control to not required 
                return this.Container.GetControl<Repeater>("repeaterItemMetaData"false); 
            } 
        } 
     
        // add logic for your control 
     
     
     

    As for the accessing items in the repeater you can use recursion.

    protected void Page_Load(object sender, EventArgs e) 
        { 
            Control lit = FindControlRecursive(this.repeaterItemMetaData, "lblKey"); 
        } 
        private Control FindControlRecursive(Control root, string id) 
        { 
            if (root.ID == id) 
            { 
                return root; 
            } 
     
            foreach (Control c in root.Controls) 
            { 
                Control t = FindControlRecursive(c, id); 
                if (t != null
                { 
                    return t; 
                } 
            } 


    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. Pierre
    Pierre avatar
    433 posts
    Registered:
    16 Feb 2006
    08 May 2009
    Link to this post
    Hi Ivan,

    Thanks but what about my guid item. No way to catch this item.ID from current view or need to found using current Title as source for filter getting all contents. I need to use to search after one internal metafield to link programatically some styles.

    Romi.
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    08 May 2009
    Link to this post
    Hi Pierre,

    You could add the following logic under Global.asax.

    // add handler on Application_Start          
    Telerik.Cms.Engine.ContentManager.Executing += new EventHandler<Telerik.ExecutingEventArgs>(ContentManager_Executing);  
          
     
        void ContentManager_Executing(object sender, Telerik.ExecutingEventArgs e)  
        {  
     
            if (e.CommandName.Equals("CreateContent"))  
            {  
                Telerik.Cms.Engine.IContent cnt = e.CommandArguments as Telerik.Cms.Engine.IContent;  
                if (cnt != null && cnt.ProviderName.Equals("News"))  
                {  
                   Guid myguid = cnt.ID;  
                } 


    All the best,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Register for webinar
4 posts, 0 answered