More in this section

Forums / General Discussions / UrlFormat for News Url

UrlFormat for News Url

7 posts, 0 answered
  1. Jamie
    Jamie avatar
    14 posts
    Registered:
    25 Mar 2011
    07 Apr 2011
    Link to this post
    Hi there, 

    Firstly I just want to say what a great product I think Sitefinity CMS is. Bravo.

    I'm a bit stuck on something. I've been trying to get rid of the date from the news url (/01/04/2011/this-is-a-test-page) and am having no luck. 

    I saw a thread on the forums about going into administration > settings > advanced > news > Providers > OpenAccessDataProviders > and adding in a new Parameter for UrlFormat. My key is UrlFormat and value is set to /special-offers/[UrlName]

    But this doesn't seem to work, despite me resetting the web server, application pool etc etc.

    Is there anywhere else that needs to be changed in order for me to get this to work please?

    Looking forward to your reply.
  2. Boyan Barnev
    Boyan Barnev avatar
    1429 posts
    Registered:
    28 Aug 2017
    07 Apr 2011
    Link to this post
    Hi Jamie,

    Thank you for contacting Telerik Support, and thank you for the nice feedback.

    Concerning the issue you are describing, please note that the key you specify is case sensitive, and you are specifying value of UrlFormat, while the proper key is urlFormat - setting this should resolve the problem. Also, please also note that you have to restart the website and you will have to make "dummy" edits to your existing items so that their Urls are recompiled.

    All the best,
    Boyan Barnev
    the Telerik team

  3. Jamie
    Jamie avatar
    14 posts
    Registered:
    25 Mar 2011
    07 Apr 2011
    Link to this post
    Brilliant that worked, thank you Boyan. 
  4. Jamie
    Jamie avatar
    14 posts
    Registered:
    25 Mar 2011
    07 Apr 2011
    Link to this post
    Another quick question, is there a way of using the newsrotator (radrotator) but displaying pages within a specific parent page instead of a list of news items?

    My code at the moment is: 

     
    protected void Page_Load(object sender, EventArgs e)
           {
               RadRotator1.DataSource = App.WorkWith().NewsItems().Where(n => n.Status == ContentLifecycleStatus.Live).Get().Take(this.NewsLimit).ToList().Join(App.WorkWith().Images().Get().Where(i => i.Parent.Title == "Promotions" && i.Status == ContentLifecycleStatus.Live), item => item.Title.Value, image => image.Title.Value, (item, image) => new { NewsItem = item, NewsImage = image });
     
               RadRotator1.ItemDataBound += new RadRotatorEventHandler(RadRotator1_ItemDataBound);
               RadRotator1.DataBind();
           }
     
           void RadRotator1_ItemDataBound(object sender, RadRotatorEventArgs e)
           {
               var link = e.Item.FindControl("newsLink") as HyperLink;
               var image = e.Item.FindControl("newsImage") as Image;
               var title = e.Item.FindControl("newsTitle") as Literal;
               var text = e.Item.FindControl("newsText") as Literal;
     
               NewsItem newsItem = (NewsItem)TypeDescriptor.GetProperties(e.Item.DataItem)["NewsItem"].GetValue(e.Item.DataItem);
               Telerik.Sitefinity.Libraries.Model.Image newsImage = (Telerik.Sitefinity.Libraries.Model.Image)TypeDescriptor.GetProperties(e.Item.DataItem)["NewsImage"].GetValue(e.Item.DataItem);
     
               if (image != null) image.ImageUrl = newsImage.MediaUrl;
               if (title != null) title.Text = newsItem.Title;
               if (text != null) text.Text = newsItem.Summary;
               if (link != null && TargetNewsPage != null) link.NavigateUrl = DataResolver.Resolve(newsItem, "URL", null, TargetNewsPage.Id.ToString());
           }
     
     
           protected PageNode TargetNewsPage
           {
               get
               {
                   if (this.targetNewsPage == null)
                   {
                       this.targetNewsPage = App.WorkWith().Pages().LocatedIn(Telerik.Sitefinity.Fluent.Pages.PageLocation.Frontend).Where(p => p.Page != null && p.Page.Controls.Where(c => c.ObjectType.StartsWith(typeof(NewsView).FullName)).Count() > 0).Get().FirstOrDefault();
     
                   } //it can still be null in case there is no page with a NewsView on it
                   return this.targetNewsPage;
               }
     
           }
     
           private PageNode targetNewsPage;
     
           public virtual int NewsLimit
           {
               get
               {
                   return this.newsLimit;
               }
               set
               {
                   this.newsLimit = value;
               }
           }
     
           private int newsLimit = 8;

    How do I get that to display a specific page within the parent page "special offers"

    Thanks,
    Jamie
  5. Boyan Barnev
    Boyan Barnev avatar
    1429 posts
    Registered:
    28 Aug 2017
    09 Apr 2011
    Link to this post
    Hello Jamie,

    Thank you for getting back to me. Can you please elaborate a little bit more on the functionality you demand? Generally it's not a problem to use the API to get pages and display links in the rotator, you can even feed them to some htmlreader and display their context, but just to make sure I got you correctly, please specify a particular use case scenario where you want this implemented.

    Best wishes,
    Boyan Barnev
    the Telerik team

  6. Jamie
    Jamie avatar
    14 posts
    Registered:
    25 Mar 2011
    12 Apr 2011
    Link to this post
    Hi Boyan,

    Thanks for replying, apologies for the delay.

    Currently, I have a special offers homepage and then child pages detailing the special offers. e.g.

    - Special Offers
              - 25% Discount
              - Kids Go Free

    I wanted to have a radrotator on the welcome page that looped through all these special child pages, but the only code I could find was the newsrotator. So, I tried the newsrotator but it just seems a bit too long winded having newsitem offers that eventually linked to the pages etc when I know the API is capable of just looping through the pages.

    I hope that makes sense.

    Thanks,
    Jamie
  7. Boyan Barnev
    Boyan Barnev avatar
    1429 posts
    Registered:
    28 Aug 2017
    18 Apr 2011
    Link to this post
    Hi Jamie,

    Thanks for the patience, and sorry about the delay. I've prepared a sample code for you which uses RadRotator to display links to all pages under a particular parent page. Please take a look at it and see if it suits your purpose. Also, please feel free to modify it according to your purposes - you can either associate some thumbnails to these links, as we are doing in the NewsRotator, or maybe use an iframe to display the pages's HTML.

    Here's the template I've set which displays a hyperlink to the page and uses the page's title for text:
    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="PageRotator.ascx.cs" Inherits="SitefinityWebApp.Controls.PageRotator" %>
    <%@ Register Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Web.UI" TagPrefix="sitefinity" %>
    <%@ Register TagPrefix="sf" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
     
    <sf:RadRotator Width="986px" Height="272" ItemWidth="986px" ItemHeight="272" id="RadRotator1" runat="server" RotatorType="AutomaticAdvance">
    <ItemTemplate>
            <asp:HyperLink runat="server" ID="pageLink" ><asp:Label runat="server" ID="pageTitle" Text='<%#Eval("Title") %>'  WrapperTagName="h2" />
            </asp:HyperLink>
         </ItemTemplate>
    </sf:RadRotator>

    and here's the code behind where I'm getting all pages whose parent is "Blank' (don't get confused, that's just how I've named my parent page):
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Telerik.Sitefinity;
    using Telerik.Sitefinity.GenericContent.Model;
    using Telerik.Sitefinity.Web.DataResolving;
    using Telerik.Sitefinity.Pages.Model;
    using Telerik.Sitefinity.Modules.Pages;
     
    namespace SitefinityWebApp.Controls
    {
        public partial class PageRotator : System.Web.UI.UserControl
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                RadRotator1.DataSource = App.WorkWith().Pages()
                                                .LocatedIn(Telerik.Sitefinity.Fluent.Pages.PageLocation.Frontend)
                                                .Where(p => p.Page != null && p.Parent.Title == "Blank" && p.Page.Status == ContentLifecycleStatus.Live)
                                                .Get();
                RadRotator1.ItemDataBound += new Telerik.Web.UI.RadRotatorEventHandler(RadRotator1_ItemDataBound);
                RadRotator1.DataBind();
            }
     
            void RadRotator1_ItemDataBound(object sender, Telerik.Web.UI.RadRotatorEventArgs e)
            {
                var link = e.Item.FindControl("pageLink") as HyperLink;
                if (link != null)
     
     
                {
                     
                    link.NavigateUrl = ((PageNode)e.Item.DataItem).GetFullUrl();
                }
            }
        }
    }
    For your convenience, I'm also attaching the control's files in an archive to this reply.I hope you find the provided sample useful and it helps you achieve the desired functionality. if you need any further assistance on this matter, please write back.

     

    Regards,
    Boyan Barnev
    the Telerik team

7 posts, 0 answered