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

Forums / General Discussions / Running server-side code on News Widget template

Running server-side code on News Widget template

3 posts, 0 answered
  1. Ryan
    Ryan avatar
    5 posts
    Registered:
    23 May 2011
    01 Sep 2011
    Link to this post
    Hi,
    I am trying to accomplish the example laid out in this post:
    http://www.sitefinity.com/blogs/joshmorales/posts/11-05-09/running_server-side_code_in_sitefinity_widget_templates.aspx

    The only difference is that I am trying to do this with the news widget instead of the events widget.  I went in to the single item news details template and added the code supplied in the example:
    <script runat="server"> protected void Page_Load(object sender, EventArgs e)
        {
            var view = this.Parent.Parent as Telerik.Sitefinity.Modules.Events.Web.UI.Public.DetailsView;
            if (view == null) return;

            var detailItem = view.Host.DetailItem;
            if (detailItem == null) return;

            Page.Title = detailItem.Title;
        }
    </script>

    However, there is no change to the title meta tag on the page- it still displays the title of the parent page.  Should this code not work for the News widget the same?  or does it need to be altered?  or does it need to be placed in a specific place within the template's code?  (I tried placing it at the beginning, the end, and the middle to no avail).  I am not a coder

    thanks!
  2. Boyan Barnev
    Boyan Barnev avatar
    1429 posts
    Registered:
    09 Dec 2016
    06 Sep 2011
    Link to this post
    Hi Ryan,

    Please excuse us for the inconvenience. For security reasons we are stripping server side code from the widget templates created/edited from Sitefninty backend since Sitefinity 4.2 official release. However, it's possible to map an external template which implements the desired functionality in the code-behind. To do so, you can use the default template applied to that particular view, and create the external template in your project. Once you've built it you can go to the widget's advanced settings -> ControlDefinition->Views and select the desired view. In the dialog there should be a TemplatePath property, wehre you should specify the application relative path to the external template in your project. Please make sure to delete the value in the TemplateKey field, as otherwise the embedded template will be loaded. Restart the application and your external temp[late will be loaded for that particular widget. If you wish to map the template globally for all instances of the widget, you can go to Administration -> Controls -> ViewMap and create a new entry there. In the HostType field enter the desired VieType (example: for News widget, details View, it will be Telerik.Sitefinity.Modules.News.Web.UI.DetailsSimpleView). In LayoutTemplate path, place the application relative path to the external template in your project. Save the changes and restart the application, an you will have your template mapped globally for all instances of the widget.

    All the best,
    Boyan Barnev
    the Telerik team

    Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

  3. SelAromDotNet
    SelAromDotNet avatar
    912 posts
    Registered:
    18 Jul 2012
    07 Sep 2011
    Link to this post
    For more examples on different ways to use external templates for your controls, take a look at these blog posts:

    Customizing Sitefinity 4 Controls with the ViewMap
    Mapping External Templates for Sitefinity 4 Widgets

    Hope this is helpful!
3 posts, 0 answered