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

Forums / Developing with Sitefinity / Single News Item not working

Single News Item not working

2 posts, 0 answered
  1. higgsy
    higgsy avatar
    336 posts
    Registered:
    05 Aug 2010
    27 Aug 2010
    Link to this post
    Hello,

    I have followed the post on http://www.sitefinity.com/devnet/forums/sitefinity-3-x/developing-with-sitefinity/master-detail-news-default-to-latest.aspx to develop a control that will simply just show the latest news article on its own.

    It works! However, no link appears to read the full story - what gives?

    My code, is exactly:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using Telerik.News;
    using Telerik.Web;
    using Telerik.Cms.Engine.ContentViewFiltering;
     
    /// <summary>
    /// Summary description for LatestNewsControl
    /// </summary>
    public class LatestNewsControl : Telerik.News.WebControls.NewsView {
         
        public LatestNewsControl() {
            //
            // TODO: Add constructor logic here
            //
        }
     
        public override string ItemListTemplatePath {
            get { return "~/Sitefinity/ControlTemplates/News/ListPageMaster.ascx"; }
        }
     
        public override string SingleItemTemplatePath {
            get { return "~/Sitefinity/ControlTemplates/News/ListPageDetails.ascx"; }
        }
     
        protected override void CreateChildControls()
        {
            // instance of NewsManager
            var man = new NewsManager("News");
            // get all items by Publication date and get the first coneten item
            var listofAll = man.Content.GetContent("Publication_Date DESC");
            var cnt = listofAll[0] as Telerik.Cms.Engine.IContent;
              
            //set the item ID
            if (Context.Items.Contains(this.Manager.Provider.ContentItemKey))
                itemId = (Guid)((IUrlRewriteData)Context.Items[Manager.Provider.ContentItemKey]).Data;
            else if (!String.IsNullOrEmpty(Context.Request[ContentItemKey]))
                itemId = new Guid(Context.Request[ContentItemKey]);
            else
            {
                itemId = cnt.ID;
            }
        
            if (this.itemId != Guid.Empty && SingleModeSupported)
            {
                ContentFilterBuilder filterBuilder = new ContentFilterBuilder(this);
                filterBuilder.AddFilter(new ContentFilterStatement("ID", itemId.ToString(), ContentFilter.Condition.Equal));
                this.CreateSingleContent();
                Controls.Add(SingleContainer);
            }
     
            base.CreateChildControls();
     
        }
     
    }

    And the file ListPageDetails.ascx is:

    <%@ Control Language="C#" %>
    <%@ Register Assembly="Telerik.Cms.Engine" Namespace="Telerik.Cms.Engine.WebControls" TagPrefix="sfWeb" %>
    <%@ Register Assembly="Telerik.Cms.Web.UI" Namespace="Telerik.Web.UI.SpamProtection" TagPrefix="sfWeb" %>
     
    <telerik:CssFileLink ID="CssFileLink1" EmbeddedFileName="Telerik.News.Resources.ControlTemplates.Frontend.newsCommonLayout.css" FileName="" Media="screen" runat="server" />
    <telerik:JsFileLink id="jsLink" runat="server" ScriptType="jQuery" />
         
    <div class="sf_singleNews">
        <asp:HyperLink ID="backToList1" Text="<%$Resources:AllNews %>" CssClass="sf_back" runat="server"></asp:HyperLink>
        <h2 class="sf_NewsTitle">
            <asp:Literal ID="Title" runat="server"></asp:Literal>
        </h2>
        <p class="sf_newsDate">
            <asp:Literal ID="Publication_Date" runat="server" Text="{0}" />
        </p>
        <p>
            <asp:Literal ID="Summary" runat="server"></asp:Literal>
        </p>
        <p>
            <asp:Literal ID="content" runat="server"></asp:Literal>
        </p>
        <p class="sf_newsAuthor">
            <asp:Literal ID="Author" runat="server"></asp:Literal>
        </p>
        <p>
            <asp:Literal ID="Source" runat="server"></asp:Literal>
        </p>
        <p class="sf_postCategory">
            <asp:HyperLink ID="Category" runat="server" />
        </p>
         
        <asp:Repeater ID="Tags" runat="server">
            <HeaderTemplate><p class="sf_postTags"></HeaderTemplate>
            <ItemTemplate>
                <asp:HyperLink ID="tagLink" runat="server" />
            </ItemTemplate>
            <FooterTemplate></p></FooterTemplate>
        </asp:Repeater>
         
         
        <asp:Repeater ID="Bookmarks" runat="server">
            <HeaderTemplate><p class="sf_postBookmark"></HeaderTemplate>
            <ItemTemplate>
                <asp:HyperLink ID="BookmarkLink" runat="server">
                    <asp:Image ID="BookmarkImage" runat="server" />
                </asp:HyperLink>
            </ItemTemplate>
            <FooterTemplate></p></FooterTemplate>
        </asp:Repeater>
         
        <div id="comments" class="sf_contentComments">
            <sfWeb:CommentsList id="commentsList" runat="server" cssclass="sf_commentsList" ValidationGroup="commentInfo"></sfWeb:CommentsList>
        </div>
    </div>

    Can anyone help?

    Thanks
    higgsy
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    30 Aug 2010
    Link to this post
    Hi Alastair,

    The code  is supposed to show a content item  directly in details mode and this is why there is no full link. The code displays the entire news item in details mode. To show the last item in master mode you need to override CrateDataSource method

    sample

    protected override System.Collections.IList CreateDataSource()
    {
     
        IList<IContent> list = new List<IContent>();
        var ds = (IContent)base.CreateDataSource()[0];
        base.CreateDataSource().Clear();
        list.Add(ds);
        return list.ToList();
    }




    Kind regards,
    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
2 posts, 0 answered