+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Changing the ItemListTemplatePath

Changing the ItemListTemplatePath

13 posts, 0 answered
  1. Siddesh Kapadi
    Siddesh Kapadi avatar
    239 posts
    Registered:
    09 Oct 2009
    29 Jul 2010
    Link to this post
    Hello Team Telerik,

    I have inherited NewsView for creating the custom control of news view. My ItemTemplatePath should be the selector for multiple templates. I have a property which finds a hyperlink on one of the template pages, it gives me an error once I change the template which does not have the hyperlink. Please let me know how can I achieve this.

    Regards,
    Siddesh Kapadi
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    29 Jul 2010
    Link to this post
    Hi Siddesh Kapadi,

    Most probably this "hyperlink" is required control and you should have it inside your template. If this is a custom hyperlink make sure that you have not set the control as required when you have made reference to it in your NewsView control. If this is one of the built-in HyperLink controls the easiest way to skip the error is to declare the control in your template and set Visible to false.

    Best wishes,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Siddesh Kapadi
    Siddesh Kapadi avatar
    239 posts
    Registered:
    09 Oct 2009
    29 Jul 2010
    Link to this post
    Hey,
    I get the folowing error:

    Property accessor 'HeaderLiteralControl' on object 'NewsViewCustomControl' threw the following exception:'Invalid resource name (Telerik.News.Resources.ControlTemplates.Frontend.Modes.ListPageMaster.ascx) for assembly (App_Code.ve8eo8vz, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null) or empty template.'

    HeaderLiteralControl is my property. declaration is as follows:

    get
            {
                return this.ListContainer.GetControl<Literal>("litHeader", false, Telerik.Framework.Web.TraverseMethod.BreadthFirst);
            }

    it gives me an error or empty template, hence ListContainer throws an exception.

    Please let me know at the earliest. I am in a big fix on this issue.

    Also, tried the above option of defining the controls with visibility false. Not working :(

    Regards,
    Siddesh Kapadi
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    29 Jul 2010
    Link to this post
    Hi Siddesh Kapadi,

    You are referencing the template embedded into Telerik.News

    Telerik.News.Resources.ControlTemplates.Frontend.Modes.ListPageMaster.ascx


    You have to override SingleItemTemplatePath and ItemListTemplatePath properties. You can set another template using the above properties. You can use the following selector - [WebEditor("Telerik.FileManager.UrlWebEditor, Telerik.FileManager") in case you want to provide an additional property for template selection.

    Greetings,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. Siddesh Kapadi
    Siddesh Kapadi avatar
    239 posts
    Registered:
    09 Oct 2009
    29 Jul 2010
    Link to this post
    Hey,
    Yes I have overriden the said properties with the following declaration:

    private string listTemplatePath = "~/Sitefinity/ControlTemplates/News/NewsSummaryWithDate.ascx";
        public override string ItemListTemplatePath
        {
            get
            {
                return listTemplatePath;
            }
            set
            {
                listTemplatePath = value;
            }
        }

        public override string SingleItemTemplatePath 
        {
            get
            {
                return "~/Sitefinity/ControlTemplates/News/ListPageDetails.ascx";
            }
        }
    The private variable listTemplatePath is set to empty, hence the ItemListTemplatePath does not seem to set and so it gives me an error. 

    Please help.

    Regards,
    Siddesh Kapadi
  6. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    29 Jul 2010
    Link to this post
    Hello Siddesh Kapadi,

    Please try something like the code bellow:
    private string listTemplatePath = "~/Sitefinity/ControlTemplates/News/NewsSummaryWithDate.ascx";
    private string itemTemplatePath = "~/Sitefinity/ControlTemplates/News/ListPageDetails.ascx";
    [WebEditor("Telerik.FileManager.UrlWebEditor, Telerik.FileManager"), Category("Appearance")]
    public override string ItemListTemplatePath
    {
        get
        {
            object obj = ViewState["ItemListTemplatePath"];
            if (obj != null)
                return (string)obj;
            return listTemplatePath;
        }
        set
        {
            ViewState["ItemListTemplatePath"] = value;
        }
    }
    [WebEditor("Telerik.FileManager.UrlWebEditor, Telerik.FileManager"), Category("Appearance")]
    public override string SingleItemTemplatePath
    {
        get
        {
            object obj = ViewState["SingleItemTemplatePath"];
            if (obj != null)
                return (string)obj;
            return itemTemplatePath;
        }
        set
        {
            ViewState["SingleItemTemplatePath"] = value;
        }
    }



    Best wishes,
    Radoslav Georgiev
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  7. Siddesh Kapadi
    Siddesh Kapadi avatar
    239 posts
    Registered:
    09 Oct 2009
    29 Jul 2010
    Link to this post
    Hey,
    It does not get set for the first time Edit, but it works correctly for the second time what might be the issue with this?


    Regards,
    Siddesh Kapadi
  8. Siddesh Kapadi
    Siddesh Kapadi avatar
    239 posts
    Registered:
    09 Oct 2009
    30 Jul 2010
    Link to this post
    Hey, I modified the code a bit now it seems to be working fine

    [code]
    private string listTemplatePath ="~/Sitefinity/ControlTemplates/News/NewsSummaryWithDate.ascx";
    private string itemTemplatePath ="~/Sitefinity/ControlTemplates/News/ListPageDetails.ascx";
    [WebEditor("Telerik.FileManager.UrlWebEditor, Telerik.FileManager"), Category("Appearance")]
    public override string ItemListTemplatePath
    {
        get
        {
            object obj = ViewState["ItemListTemplatePath"];
            if (obj != null)
                return (string)obj;
            return listTemplatePath;
        }
        set
        {
       if(value != null)
                ViewState["ItemListTemplatePath"] = value;
        }
    }
    [WebEditor("Telerik.FileManager.UrlWebEditor, Telerik.FileManager"), Category("Appearance")]
    public override string SingleItemTemplatePath
    {
        get
        {
            object obj = ViewState["SingleItemTemplatePath"];
            if (obj != null)
                return (string)obj;
            return itemTemplatePath;
        }
        set
        {
       if(value != null)
                 ViewState["SingleItemTemplatePath"] = value;
        }
    }
    [/code]
  9. Siddesh Kapadi
    Siddesh Kapadi avatar
    239 posts
    Registered:
    09 Oct 2009
    02 Aug 2010
    Link to this post
    Hey,

    I am using the same code for changing the template of blogposts. The ItemListTemplatePath is changing but the default value is taken into consideration. How can this occur or am I performing the wrong steps or for blogpost is it managed different way.

    Regards,
    Siddesh Kapadi
  10. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    02 Aug 2010
    Link to this post
    Hello Siddesh Kapadi,

    This is a problem of the blog posts control. You have to set the property twice in order to set it. I am using this code and the result is the same:
    using Telerik.Blogs.WebControls;
     
    /// <summary>
    /// Summary description for CustomBlogPosts
    /// </summary>
    public class CustomBlogPosts:BlogPosts
    {
        #region Properties
        [Telerik.Cms.Web.UI.WebEditor("Telerik.FileManager.UrlWebEditor, Telerik.FileManager"),
        System.ComponentModel.Category("Appearance")]
        public override string ItemListTemplatePath
        {
            get
            {
                object obj = ViewState["ItemListTemplatePath"];
                if (obj != null)
                    return (string)obj;
                return itemListTemplatePath;
                 
            }
            set
            {
                ViewState["ItemListTemplatePath"] = value;
            }
        }
     
     
        [Telerik.Cms.Web.UI.WebEditor("Telerik.FileManager.UrlWebEditor, Telerik.FileManager"),
        System.ComponentModel.Category("Appearance")]
        public override string SingleItemTemplatePath
        {
            get
            {
                object obj = ViewState["SingleItemTemplatePath"];
                if (obj != null)
                    return (string)obj;
                return singeItemTemplatePath;
            }
            set
            {
                ViewState["SingleItemTemplatePath"] = value;
            }
        }
        #endregion
     
        #region Fields
     
        private string singeItemTemplatePath = "~/Sitefinity/ControlTemplates/Blogs/ContentViewItemList.ascxv";
        private string itemListTemplatePath = "~/Sitefinity/ControlTemplates/Blogs/ContentViewItemList.ascx";
     
     
        #endregion
    }


    Kind regards,
    Radoslav Georgiev
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  11. Siddesh Kapadi
    Siddesh Kapadi avatar
    239 posts
    Registered:
    09 Oct 2009
    02 Aug 2010
    Link to this post
    Hey,
    How is it that I have to set the properties twice, If yoou can give me the example of what you mean woould be of great help!!!

    Regards,
    Siddesh Kapadi
  12. Siddesh Kapadi
    Siddesh Kapadi avatar
    239 posts
    Registered:
    09 Oct 2009
    03 Aug 2010
    Link to this post
    Hey,
    The multiple selection is not for BlogPosts Class only but also for NewsView Class as well. I have chaged the code above for the same reasons. But the issue I am currently facing is the Itemtemplate is set for the first time when I am inheriting Blogsposts, but the changed template is not loaded but the default template is taking the effect, even if the ItemListTemplatePath is set to a different one. Please let me know how this can be changed / corrected.

    Regards,
    Siddesh Kapadi
  13. Richard Baugh
    Richard Baugh avatar
    201 posts
    Registered:
    22 Aug 2012
    18 Aug 2010
    Link to this post
    I too have noticed this as well. We created a control that was based off the ContentView control. When overriding the ItemListTempaltePath, we are passing in an internal template as the default. When adding the control to a page and setting the value of the property, it ignores the external template specified and uses the internal template. I even stepped through the code and noticed that the ItemListTemplate was being called and instatiated before the ItemListTemplatePath was set via the properties assigned to via the UI. I checked the following, base.ChildControlsCreated, and it was false when the ItemListTemplate was called and instantiated.

    What I finally did to get this to work was to set the ItemListTemplate to null when the ItemListTemplatePath is set.
    public override string ItemListTemplatePath
    {
        get
        {
            return base.ItemListTemplatePath;
        }
        set
        {
            base.ItemListTemplatePath = value;
            base.ItemListTemplate = null;
        }
    }
    This will force the ItemListTemplate to recreate itself using the ItemListTemplatePath value.

    I looked over a few other threads that were related to this and none of them seemed to have helped. Things I also tried:
    1) Set the ItemListTemplatePath and ItemListTemplatePath under SelectedPresentationMode settings - No luck
    2) Removed the control and added a new instance. Set the properties before saving the page - This seemed to have worked for a bit, but a fellow colleague edited the control, not changing the template info, saved the page and now it shows fine for preview and edit but not live. (workflow off)
    3) I tried to specify a template, ascx file, that was not in the file system and this did throw an error, changed it back to a control that exists and still displays internal template.

    Just for your information, we are running 3.7SP3.
Register for webinar
13 posts, 0 answered