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

Forums / Developing with Sitefinity / Change HTML Control

Change HTML Control

9 posts, 0 answered
  1. Romain
    Romain avatar
    10 posts
    Registered:
    18 Feb 2009
    23 Feb 2009
    Link to this post
    Hello everybody !

    I'm really new in coding with Sitefinity (and also in .NET techno).

    I'm searching where to change the HTML of a module (News in particular but other will be fine too) ?

    I just finished to watch the entire video support, but I don't see this info yet, because of different version of Sitefinity use in the video I think...
    Also don't find it in the developer manual...

    Thank you !
  2. Romain
    Romain avatar
    10 posts
    Registered:
    18 Feb 2009
    23 Feb 2009
    Link to this post
    I'm pretty sure that someone can help me... It's really a newbie question ! :)
  3. Mike
    Mike avatar
    208 posts
    Registered:
    10 Dec 2007
    23 Feb 2009
    Link to this post

    Hi Romain,

    This might have changed a bit in SF 3.6 but I haven't yet downloaded it.  In Sitefinity 3.5, you can modify the control templates for the control.  There's one that renders the HTML for the list, and another one that renders the HTML for a single item.

    The control templates are located in:

    \<project folder>\Sitefinity\ControlTemplates

    So, for example, to change the News single item template, open:

    \<project folder>\Sitefinity\ControlTemplates\News\SingleNews.ascx

    and make your changes.

    This will get you started, but you should note, however, that editing a file that comes with Sitefinity could result in problems down the road if you upgrade--the upgrade could replace your customized version with the out-of-the-box version.  So I always create a copy of the ConntrolTemplate, as well as a copy of the resource file which is named the same as the control template, with a ".resx" extension. 

    Then you can override the ControlTemplate path (there are two, one for the single item and one for the list) in the control itself when you drag it onto the page.

    If you want to override ALL instances of your control, there is a way to do that without having to edit each one when you create a page.  But it's a lot more complicated.  I'll list the steps here, but if you're not a .NET techno, it's going to be confusing.

    Basically you create a new control that inherits the standard Sitefinity one.  Then you override the SingleItemTemplatePath and the ItemListTemplatePath.  You can then edit the web.config to add your control or replace the Sitefinity control with your new one.  This is detailed somewhere in the help documentation, but an example is below:

    Example

    CustomContentView.cs (place this in App_Code)

    using System;  
    using System.Collections.Generic;  
    using System.Data;  
    using System.Configuration;  
    using System.Text;  
    using System.Web;  
    using System.Web.Security;  
    using System.Web.UI;  
    using System.Web.UI.HtmlControls;  
    using System.Web.UI.WebControls;  
    using System.Web.UI.WebControls.WebParts;  
     
    using Telerik.Cms.Engine.WebControls;  
    using Telerik.Cms.Engine;  
    using Telerik.Web;  
     
     
    namespace CollaborationPeople.Sitefinity  
    {  
        /// <summary>  
        /// CustomContentView extends the existing Sitefinity ContentView control  
        /// </summary>  
        public class CustomContentView : ContentView  
        {
            #region Overriden properties  
     
            /// <summary>  
            /// Gets or sets the path of the template used by this control when control is displaying the list  
            /// </summary>  
            /// <remarks>  
            /// The reason we are overriding this property is to set different default value  
            /// </remarks>  
            public override string ItemListTemplatePath  
            {  
                get 
                {  
                    object obj = this.ViewState["ItemListTemplatePath"];  
                    if (obj != null)  
                        return (string)obj;  
                    // otherwise return default path of the ItemList Template. This should be the path  
                    // of the new template we have created  
                    return "~/Sitefinity/ControlTemplates/CustomContent/ContentViewItemList.ascx";  
                }  
                set 
                {  
                    this.ViewState["ItemListTemplatePath"] = value;  
                }  
            }  
     
            /// <summary>  
            /// Gets of sets the path of the template used by this control when control is displaying one item  
            /// </summary>  
            /// <remarks>  
            /// The reason we are overriding this property is to set different default value  
            /// </remarks>  
            public override string SingleItemTemplatePath  
            {  
                get 
                {  
                    object obj = this.ViewState["SingleItemTemplatePath"];  
                    if (obj != null)  
                        return (string)obj;  
                    // otherwise return default path of the SingleItem Template. This should be the path  
                    // of the new template we have created  
                    return "~/Sitefinity/ControlTemplates/CustomContent/ContentViewSingleItem.ascx";  
                }  
                set 
                {  
                    this.ViewState["SingleItemTemplatePath"] = value;  
                }  
            }  
        }  
    }  
     

     

    And the web.config would be modified like:

    This approach lets  you modify all sorts of things, and also lets you create new metadata fields and insert their values in the HTML.

    Regards,
    Mike Sharp

     

     

     

    <toolboxControls> 
    [...]Other Toolbox Controls[...]  
        <add name="Custom Control" section="My Custom Controls" type="CollaborationPeople.Sitefinity.CustomContentView, App_Code" /> 
    </toolboxControls> 
     
  4. Dido
    Dido avatar
    149 posts
    Registered:
    24 Sep 2012
    24 Feb 2009
    Link to this post
    Hi Mike,

    What Mike said is still the same in general in Sitefinity 3.6.

    Here are some differences, though:
    • Sitefinity now uses Embedded Templates. That is, Sitefinity will no longer override your custom templates.
    • In order to use them, you need to follow the steps in this KB Article. Shortly put, you tell Sitefninty which control you want to override, copy the default template and associated resources, and finally - edit.

    Generally, Sitefinity tries to use your custom templates, but if you have provided none, it will use its Embedded Templates.

    If you need further assistance, please feel free to contact us.

    Greetings,
    Dido
    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.
  5. Romain
    Romain avatar
    10 posts
    Registered:
    18 Feb 2009
    02 Mar 2009
    Link to this post
    Wow !!! It's not simple at all !!! Just to replace a little HTML structure !!!

    But OK, I did it !

    I create the configuration file and the template on the correct place, I only left the template empty. Just for test... So I just click on Modules tab... The login screen appear (after only 5min logged) and I can't login with any account ! I try the database modification to restore password (PasswordFormat = 0) but it didn't change anything.

    Does someone know an issue to restore this ?!? Why create a conf and template file can modify the login mechanism ???
  6. Romain
    Romain avatar
    10 posts
    Registered:
    18 Feb 2009
    02 Mar 2009
    Link to this post
    Ok.....

    I delete file, it didn't work.
    I restart SQL Server, it didn't work.
    I restart IIS, it didn't work.
    I restart my computer, hopefully I work in local, it works !
    I mean login works !

    So I re-create the config file
    <?xml version="1.0" encoding="utf-8" ?> 
    <controlsConfig> 
        <viewMap> 
            <viewSettings hostType="Telerik.News.WebControls.Admin.NewsItemNew" layoutTemplatePath="~/Sitefinity/Admin/ControlTemplates/News/NewsItemNew.ascx" /> 
        </viewMap> 
    </controlsConfig> 

    re-create the template file :
    <%@ Control Language="C#" ClassName="NewsItemNew" %>  
     
    <script runat="server">  
    Hello world !  
    </script> 

    And login just loop on login screen without displaying any errors !

    I have to restart my computer again !!!

    Does anyone can help please ?
  7. Romain
    Romain avatar
    10 posts
    Registered:
    18 Feb 2009
    02 Mar 2009
    Link to this post
    Maybe it's because I don't create a ressource file for this template in App_LocalRessource... I download the zip file which should help me but I donno which file do I copy for example for the new's item !

    Can I have a clear and working answer ?
  8. Romain
    Romain avatar
    10 posts
    Registered:
    18 Feb 2009
    02 Mar 2009
    Link to this post
    I try another way...

    I get all the 3.5 files for the list's template. Admin doesn't crash, yes !
    I write the filename in every .ascx file, to know which file used in my template (in the admin I use "Simple list"). But I didn't notice any change !!!! (IIS, IE, SQL restarted)

    Why I have to download 3.5 files to have externals templates working ?
    Why can I not see any changes in thus templates ?
    Should we set up that a config file (Telerik.Sitefinity.Configuration.ControlsConfig.xml) was added ?
  9. Ivan
    Ivan avatar
    478 posts
    Registered:
    16 Jun 2015
    03 Mar 2009
    Link to this post
    Hi Romain,

    this blog posts outlines step-by-step instructions on how to map the external templates:
    http://blogs.sitefinity.com/Ivan/Posts/09-02-23/Mapping_a_control_to_use_external_template.aspx

    If you are looking to map templates of ListDisplay control, then you should also consult this blog post:
    http://blogs.sitefinity.com/Ivan/Posts/09-02-23/Mapping_multiple_templates_of_control.aspx

    The KB article you were referred to, unfortunately had some wrong information for about 10 days, which are fixed now, so it could be that we have pointed you in a wrong direction and I truly apologize for this.

    I hope you will find this information helpful. Let us know if there is anything else we can do for you.

    Sincerely yours,
    Ivan
    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
9 posts, 0 answered