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

Forums / Developing with Sitefinity / How to Store ITemplate in a Resource File

How to Store ITemplate in a Resource File

9 posts, 0 answered
  1. Jim
    Jim avatar
    5 posts
    Registered:
    12 Jun 2007
    23 Mar 2009
    Link to this post
    Hi,

    My company is using Sitefinity to deliver a CMS to one of our customers. Out of the box it handles 90% of their needs and for the other 10% I have built them a custom Module that has several controls and control designers. Developing with the product has been great from day one compaired to other CMS systems we ahve used in the past. Now we are nearing deployment to production and I would like to store all the User Controls in a resource file to make the deployment and maintance a little easier and am not sure how to go about it. Also, I only have the rest of this week to do it if it's going to happen so any help owuled be greatly appreciated.

    What I am doing now is exactly what is described in the documentation. I have the ascx controls in the site and then specify the paths in the compiled class like so.

    public string LayoutTemplatePath  
            {  
                get 
                {  
                    object obj = this.ViewState["LayoutTemplatePath"];  
                    if (obj != null)  
                        return (string)obj;  
                    return "~/Sitefinity/ControlTemplates/StudentInfoPublicControls/AsemMarketing.ascx";  
                }  
            }  
            public ITemplate LayoutTemplate  
            {  
                get 
                {  
                    template = ControlUtils.GetTemplate<DefaultTemplate>(LayoutTemplatePath);  
                    return template;  
                }  
                set 
                {  
                    template = value;  
                }  
            } 

    I tried just putting the ascx control in a resource file and then castig the string as an ITemplate but that didn't work. Is there an elegant solution so I can have everything compiled into the one DLL?

    Thanks in advance.
  2. Slavo
    Slavo avatar
    295 posts
    Registered:
    24 Sep 2012
    24 Mar 2009
    Link to this post
    Hello Jim,

    It is possible to achieve what you need in Sitefinity 3.6 after we introduced embedded templates. However, there are two sides of the story. First, for each control you have the class itself (or the control type). This is the classs that you've taken the provided code from. Then you have a layout template, which is an ascx file. Having this ascx DOES NOT mean that you are using user controls. It could still be a custom control, the ascx is only used for a template. This is the case with all built-in modules in Sitefinity.

    If this is you case too (in fact developing a pluggable module), then you can use embedded templates. See the Contacts sample module for a way to do this:

    You can also check out the other articles from Ivan's series for further info about the new backend architecture:

    Kind regards,
    Slavo
  3. Jim
    Jim avatar
    5 posts
    Registered:
    12 Jun 2007
    24 Mar 2009
    Link to this post

    Thank you for your quick response. After downloading the ContactList Sample Project and looking it over I can see that embedded templates is exactly what I am trying to accomplish. I am having a little trouble getting the sample code to work out for me though. It is as if I am missing some classes or assemblies. I downloaded the project from the link you provided. Here is where I am having a little trouble.

    I can see that here is where he is linking to the embedded template. But I seem to be missing a reference in the project to use the WebSysTemplate attribute.

    /// <summary>  
            /// Gets or sets the path to a custom layout template for the control.  
            /// </summary>  
            [WebSysTemplate(SingleContact.SingleContactTemplateName  
                , "SingleContact_Template_Desc""/Contacts/"false"2009-02-20")]  
            public override string LayoutTemplatePath  
            {  
                get 
                {  
                    return base.LayoutTemplatePath;  
                }  
                set 
                {  
                    base.LayoutTemplatePath = value;  
                }  
            }  
     
            /// <summary>  
            /// Gets the name of the embedded layout template.  
            /// </summary>  
            public override string LayoutTemplateName  
            {  
                get 
                {  
                    return SingleContact.SingleContactTemplateName;  
                }  
            } 
    I found this article here.

    http://blogs.sitefinity.com/Ivan/Posts/09-03-21/Products_module_Reusing_Views.aspx

    Which implies that this attribute may be part of the 4.0 release.

    "The only reason why we are overriding LayoutTemplatePath property is to declare the WebSysTemplate attribute on it which will be used by the template management tool to be introduced in Sitefinity 4.0. "

    I added refferences to his project for what appeard to be all the required assemblies but the attribute is still not found. I also need some documentation on what each of the parameters of the attribute are for as I cant seem to find where this attribute is documented.

    Thanks again for all you help.

  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    24 Mar 2009
    Link to this post
    Hello Jim,

    The webSysTemplate is used when you want to have embedded templates for your view. Then, LayoutTemplateName and LayoutTemplatePath properties are overridden.

      internal class WebSysTemplate : EmbeddedTemplateAttribute 
        { 
            public WebSysTemplate(string resourceName, string description 
                , string defaultExtPaht, bool isFrontEnd, string lastModified) 
                : base(resourceName, description, defaultExtPaht, isFrontEnd, lastModified) 
     
           ..... 
              ...... 

    As you see WebSysTemplate inherits from  public class EmbeddedTemplateAttribute. If you need further assistance, write back us.

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Check out Telerik Trainer , the state of the art learning tool for Telerik products.
  5. Jim
    Jim avatar
    5 posts
    Registered:
    12 Jun 2007
    24 Mar 2009
    Link to this post
    I must require the patch.
  6. Ivan
    Ivan avatar
    478 posts
    Registered:
    16 Jun 2015
    24 Mar 2009
    Link to this post
    Hi Jim,

    here is some background on the WebSysTemplate class: because the class is using resource manager class (which Microsoft implemented as an internal class in .NET) it is necessary that the WebSysTemplate class is located in the same assembly as the class that uses it - in other words: for every module you must implement this class.

    The implementation is really simple and you can copy it directly from the contacts module and paste it in your module - you don't have to change anything - it just have to be in your assembly.

    We are aware that this is not exactly the perfect solution and are trying to come up with a more elegant solutions for Sitefinity 4.0, however, for the moment being the class has to be in every assembly that embeds templates - we hope it's not too much of an inconvenience.

    Let us know if there is anything else we can do for you.

    Regards,
    Ivan
    the Telerik team

    Check out Telerik Trainer , the state of the art learning tool for Telerik products.
  7. Jim
    Jim avatar
    5 posts
    Registered:
    12 Jun 2007
    24 Mar 2009
    Link to this post
    Where is The public class EmbeddedTemplateAttribute located? I am not seeing it in the Sample contacts project, and it's not a .NET Class.
  8. Jim
    Jim avatar
    5 posts
    Registered:
    12 Jun 2007
    24 Mar 2009
    Link to this post
    I need the base class. It is not included in the Contacts Sample Project...
  9. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    24 Mar 2009
    Link to this post
    Hello Jim,

    EmbeddedTemplateAttribute uses Telerik.Web namespace. Also
    public class EmbeddedTemplateAttribute inherits Attribute


    Check out the sample below

    using Telerik.Web;
        
    [AttributeUsage(AttributeTargets.Property)]  
        internal class WebSysTemplate : EmbeddedTemplateAttribute  
        {  
            public WebSysTemplate(string resourceName, string description  
                , string defaultExtPaht, bool isFrontEnd, string lastModified)  
                : base(resourceName, description, defaultExtPaht, isFrontEnd, lastModified)  
            {  
            }  
     
            /// <summary>  
            /// Gets the description.  
            /// </summary>  
            /// <value>The description.</value>  
            public override string Description  
            {  
                get 
                {  
                    return Messages.ResourceManager.GetString(base.Description);  
                }  
            }  
     
            /// <summary>  
            /// When implemented in a derived class, gets a unique identifier for this <see cref="T:System.Attribute"/>.  
            /// </summary>  
            /// <value></value>  
            /// <returns>An <see cref="T:System.Object"/> that is a unique identifier for the attribute.</returns>  
            public override object TypeId  
            {  
                get 
                {  
                    return typeof(EmbeddedTemplateAttribute);  
                }  
            }  
        } 


    All the best,
    Ivan Dimitrov
    the Telerik team

    Check out Telerik Trainer , the state of the art learning tool for Telerik products.
Register for webinar
9 posts, 0 answered