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

Forums / Developing with Sitefinity / Using Embedded Templates with Controls Derived from ContentView

Using Embedded Templates with Controls Derived from ContentView

8 posts, 0 answered
  1. John
    John avatar
    14 posts
    Registered:
    07 Nov 2008
    29 Sep 2009
    Link to this post
    I've been developing controls derived from the ContentView control, overriding the SingleItemTemplatePath and ItemListTemplatePath properties, and supplying the appropriate templates in those locations.

    However, I'd much rather override the SingleItemTemplateName or ItemListTemplateName properties, and use an embedded template. But I try to do so, I get an error saying that the template can't be found since it's looking for the embedded resouce in the Telerik.CMS.Engine assembly rather than mine.

    Is there any way around this? Using embedded templates would be much better for portability in our custom modules.

    Thanks!
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    30 Sep 2009
    Link to this post
    Hi John,

    It is not possible to use the embedded templates from a different assembly in your custom controls. You should override LayoutTemplatePath property and SingleItemTemplate path and return your templates.

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Pierre
    Pierre avatar
    433 posts
    Registered:
    16 Feb 2006
    30 Sep 2009
    Link to this post
    Hi,
    Could you explain more about use these embeded resources. What is the utility of WebSysDescriptionAttribute.cs and WebSysTemplate.cs?. I have added some style sheet and i can´t use, not loading 404 error but are here. I have tried registrering this. Is mandatory registering in assembly.cs file with mime types?. Have you others utilities that can make this .

    protected void LoadStyles()  
            {  
                // Retrieve a list of resource names contained by the assembly.  
                //exposed adding in Assembly.cs  
                //[assembly: WebResource("MyWebAppAssembly.MyStylesheet.css","text/css", PerformSubstitution = true)]  
                //Assembly assembly = Assembly.GetExecutingAssembly();  
                //document.write("<img src='<%=WebResource("MyWebResourceProj" + ".MyResources.Test.gif")%>'>");  
                string assemblyName = this.GetType().Assembly.FullName;  
                string[] resourceNames = this.GetType().Assembly.GetManifestResourceNames();  
                Page page = HttpContext.Current.Handler as Page;  
                foreach (string resourceName in resourceNames)  
                {  
                    if (resourceName.EndsWith(ToModel + ".css"))
                    {  
                        string webResourceUrl = page.ClientScript.GetWebResourceUrl(this.GetType(), resourceName);  
                        string includeTemplate = "<link class='Embeded-" + resourceName + "' rel='stylesheet' type='text/css' href='{0}' />";  
                        page.Header.Controls.Add(new LiteralControl(String.Format(includeTemplate, webResourceUrl)));  
                        //((HtmlHead)Page.Header)  
                    }  
                }  
            } 

    Romi
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    01 Oct 2009
    Link to this post
    Hello Pierre,

    WebSysTemplate defines the attribute for specifying embedded templates. WebSysTemplate attribute class needs to be implemented in every assembly that will use embedded templates. WebSysTemplate attribute  will be used by the template management tool to be introduced in Sitefinity 4.0. You should use WebSysTemplate attribute in a properties to get or set the path to a custom layout template for a control.

    You should pass the parameters highlighted below:

    WebSysTemplate(string resourceNamestring description  
                , string defaultExtPahtbool isFrontEndstring lastModified)  
                : base(resourceName, description, defaultExtPaht, isFrontEnd, lastModified)  


    Greetings,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  5. Pierre
    Pierre avatar
    433 posts
    Registered:
    16 Feb 2006
    02 Oct 2009
    Link to this post
    Hi,

    How to use ? Could you post some sample to undesrtand the utility for distribute our sources. Thanks good we.
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    04 Oct 2009
    Link to this post
    Hi Pierre,

    I sent a reply to the other post you opened. There you will find a sample code.

    All the best,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  7. bemara57
    bemara57 avatar
    135 posts
    Registered:
    27 Mar 2008
    10 Feb 2010
    Link to this post
    Hi Ivan,

    Is this still not possible in the latest 3.7? I have my own assembly library that I'd like an embedded template to be used. SingleItemTemplateName still gives errors about not finding my embedded template in Telerik's assembly... but I put the full namespace and file name in the SingleItemTemplateName section of ControlsConfig.

    This would really help keep my customizations separate from the core code base of Sitefinity. Any suggestions on how to structure my custom templates so they are not mixed in with the core code base?
  8. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    11 Feb 2010
    Link to this post
    Hi bemara57,

    In the previous post I made to Romi there is a link which shows how to embed a template in a custom class library and compile it to a dll. Below is another sample that you can observe

    namespace SampleViewCustomControl
    {
        public class SampleControl : ContentView
        {
            public override string ItemListTemplateName
            {
                get
                {
                    return SampleControl.SampleViewCustomItemListTemplateName;
                }
            }
     
           
            public override string SingleItemTemplateName
            {
                get
                {
                    return SampleControl.SampleViewCustomSingleItemTemplateName;
                }
            }
     
            public override Type AssemblyInfo
            {
                get
                {
                    return typeof(SampleControl);
                }
                set
                {
                    base.AssemblyInfo = value;
                }
            }
     
     
     
            #region Constants
     
            private const string SampleViewCustomItemListTemplateName = "SampleViewCustomControl.Resources.ListPageMaster.ascx";
     
            private const string SampleViewCustomSingleItemTemplateName = "SampleViewCustomControl.Resources.ListPageDetails.ascx";
     
            #endregion
        }
    }


    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
    Follow the status of features or bugs in PITS and vote for them to affect their priority.
Register for webinar
8 posts, 0 answered