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

Forums / Developing with Sitefinity / Editing News View for add functionality

Editing News View for add functionality

12 posts, 2 answered
  1. xax_007
    xax_007 avatar
    55 posts
    Registered:
    24 Jul 2009
    10 Dec 2009
    Link to this post
    Hello,

    I have problems editing NewsViewControlDesigner.ascx, I would like add funcionality for diplay news,

    i added a Boolean in News maintenance that say me if is in home page or no, and i would like say to sitefinity news display, that this new will be diplayed in a page.
    Other radiobutton that say sitefinity the news with this boolean a true are diplayed.

    What is the method o object for do this?

    Is posible?

    I need use my boolean.


    In Spanish:

    Necesito añadirle funcionalidad al selector de noticias que seran mostradas desde el visor de noticias, quiero que a partir de un boleano que me he definido en el mantenimiento de noticias decirle al visor de sitefinity que me muestre esa noticia. es decir, igual que tiene seleccionar por categoria quiero otro radbutton que sea seleccionar las que van en portada, pero internamente ¿de que clase tengo que heredar y cuales son los metodos o objetos que tengo que crear para que en el visor me muestre las noticias que esten con esa variable?

    Thanks

    Salu2,
    Pablo
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    10 Dec 2009
    Link to this post
    Hello xax_007,

    You have to override NewsView control and implement the boolean type property.

    [System.ComponentModel.Category("TEST")]
        public bool IsHome
        {
            get
            {
                return this._IsHome;
            }
            set
            {
                this._IsHome = value;
            }
        }
        private bool _IsHome;

    Then you can override one of the following methods - CreateChildControls(), SetItemMetadata(), SetSingleItemContent, but it depends on what is the desired result.


    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. xax_007
    xax_007 avatar
    55 posts
    Registered:
    24 Jul 2009
    10 Dec 2009
    Link to this post
    Thanks for reply Ivan,

    Now the methods are override, but i don´t know what propertie is necessary for my cutom view, for example.

    When my new is with this boolean true, i would like say to this propertie that filters by this,

    I do a foreach in news I catch the metadata true o false, but i don´t know witch propertie or properties are right for this.

    Thank again.

    In Spanish:

    Ya tengo los metodos sobreescritos, pero ahora me falta saber que propertie es la necesaria para decirle a la vista que me filtre por mis parámetros, es decir, si quiero que la vista me filtre cuando hago un bucle por las noticias y estas tienen mi variable a true, que tengo que cambiar al heredar de NewsView?

    Gracias de nuevo.

    Salu2,
    Pablo
     
    Telerik.News.NewsManager nM = new Telerik.News.NewsManager("News");   
     
    IList news = nM.Content.GetContent();   
     
    foreach (Telerik.Cms.Engine.IContent myNew in news)   
    {  
        if (Boolean.Parse(myNew.GetMetaData("inHome").ToString()))   
        {  
            //I dont know how say sitefinity that diplay this in my view   
        }  
    }  
     

     

     

     

     

     

     

     


  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    11 Dec 2009
    Link to this post
    Hello xax_007,

    Give a try to the code below:

    Telerik.News.NewsManager nM = new Telerik.News.NewsManager("News");
    IList news = nM.Content.GetContent();
    foreach (Telerik.Cms.Engine.IContent myNew in news)
    {
        // if the condition is true
        if (_IsHome)
        {
           // add some logic
        }
        // condition is not true
        else
        {
            // add other logic
        }
    }

    All the best,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  5. xax_007
    xax_007 avatar
    55 posts
    Registered:
    24 Jul 2009
    14 Dec 2009
    Link to this post

    Hello,

    I will do this:

    In NewsView edit the template for display My News selection.

    (View Image)

    And when I select My News selection, do a new view with my news that has got metadata isHome true.

    I would like to know how to make the API as add my new view with my selected news.

     

    Thanks

  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    14 Dec 2009
    Link to this post
    Hello xax_007,

    You need to override the NewsView control and get reference to the control designer from where you can check whether your property is selected or not. 

    Below is a sample implementation

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using Telerik.Cms.Engine.WebControls.Design;
    using Telerik.Framework.Web;
    using System.Web.UI.WebControls;
     
    /// <summary>
    /// Summary description for NewsViewDesignerCustom
    /// </summary>
    public class NewsViewDesignerCustom : ContentViewDesignerBase
    {
        public NewsViewDesignerCustom()
        {
        }
     
     
        public override string DesignerTemplatePath
        {
            get
            {
                return "~/Sitefinity/Admin/ControlTemplates/News/NewsViewControlDesigner.ascx";
                //ControlUtils.GetTemplate
            }
     
        }
     
        public override string LayoutTemplatePath
        {
            get
            {
                return "~/Sitefinity/Admin/ControlTemplates/News/NewsViewControlDesigner.ascx";
            }
        }
     
        // IsHome IS OUR PROPERTY THAT WE SET
        // THE PROPERTY IS DEFINED IN OUR CUSTOM NEW VIEW CONTROL
        protected override void InitializeComponent()
        {
            base.InitializeComponent();
            if (Box != null)
            {
                if (Box.Checked)
                    ((NewsListCustomized)DesignedControl).IsHome = true;
             ((NewsListCustomized)DesignedControl).IsHome = false;
               
            }
        }
     
        public override void OnSaving()
        {
            base.OnSaving();
            if (Box != null)
            {
                if (Box.Checked)
                    ((NewsListCustomized)DesignedControl).IsHome = true;
                ((NewsListCustomized)DesignedControl).IsHome = false;
     
            }
        }
     
     
        // CREATE A REFERENCE TO THE CONTROL IN THE DESIGNER
        public virtual CheckBox Box
        {
            get
            {
                return this.Container.GetControl<CheckBox>("CheckBox1", true);
            }
        }
     
     
    }


    Greetings,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
    Answered
  7. xax_007
    xax_007 avatar
    55 posts
    Registered:
    24 Jul 2009
    14 Dec 2009
    Link to this post
    Thanks, thanks and thank this reply is exactly I need,

    This is only NewsDesigner,

    Is this correctly for NewsViewCustom control or i forget something?

    [ControlDesigner("NewsView.NewsDesignerCustom, NewsView")]    
        public class NewsViewCustom: Telerik.News.WebControls.NewsView  
        {  
     
            public Boolean InHome { getset; }  
     
            public NewsViewCustom()  
            {  
                  
            }  
     
            protected override IList CreateDataSource()  
            {  
     
                Telerik.News.NewsManager nM = new Telerik.News.NewsManager("News");  
     
                IList news = nM.Content.GetContent();  
     
                foreach (Telerik.Cms.Engine.IContent myNew in news)  
                {  
                      
                    if (Boolean.Parse(myNew.GetMetadata("InHome").ToString()))  
                    {  
                         news.Add(myNew);  
                    }  
                }  
     
                return news;  
            }  
        } 

    Could give me an example as above for News View?

    Thanks

    Salu2,
    Pablo
  8. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    14 Dec 2009
    Link to this post
    Hello xax_007,

     Below is a sample code with comments:

    // HERE YOU DECLARE THE DESIGNER LIKE ("NAMESPACE, ASSEMBLE")
    [ControlDesignerAttribute("NewsViewDesignerCustom, App_Code")]
    class NewsCustomized : NewsView
    {
        
     
        
        // OVERRIDE THE TEMPLATES FOR SINGLE AND DETAIL MODE AND SET THE TEMPLATES
        // FOR YOUR CONTROL
        public override string ItemListTemplatePath
        {
            get { return "~/Sitefinity/ControlTemplates/News/ListPageMaster.ascx"; }
        }
     
        public override string SingleItemTemplatePath
        {
            get { return "~/Sitefinity/ControlTemplates/News/ListPageDetails.ascx"; }
        }
     
         // OVERRIDE OTHER METHODS TO ADD YOUR CUSTOM LOGIC.
    }

    All the best,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
    Answered
  9. xax_007
    xax_007 avatar
    55 posts
    Registered:
    24 Jul 2009
    28 Dec 2009
    Link to this post

    Hello, this not work:

    [ControlDesigner("NewsView.NewsDesignerCustom, NewsView")]       
        public class NewsViewCustom: Telerik.News.WebControls.NewsView     
        {     
        
            public Boolean InHome { getset; }     
        
            public NewsViewCustom()     
            {     
                     
            }     
        
            protected override IList CreateDataSource()     
            {     
        
                Telerik.News.NewsManager nM = new Telerik.News.NewsManager("News");     
        
                IList news = nM.Content.GetContent();     
        
                foreach (Telerik.Cms.Engine.IContent myNew in news)     
                {     
                         
                    if (Boolean.Parse(myNew.GetMetadata("InHome").ToString()))     
                    {     
                         news.Add(myNew);     
                    }     
                }     
        
                return news;     
            }     
        }   
     

    override createdatasource not do my list of news...

    Have I do something more?

    NewsViewCustom display all news, not my news with boolean true.

    In createdatasource y get my news but NewsViewCustom not diplay this...

    Have you example for this?

    Thanks and Salu2,
    Pablo
  10. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    28 Dec 2009
    Link to this post
    Hello xax_007,

    I suggest that you should use ContentFilterbuilder class to filter the items instead of creating IList, then checking the metakey and add some items to the list. You have to create a new instance of ContentFilterBuilder class and add ContentFilterStatement. You just have to apply the filter only in case that your boolean property is checked. You can apply the filter in CreateContentList method before you call the base. You should be able to do it in CreateChildControls as well.

    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  11. xax_007
    xax_007 avatar
    55 posts
    Registered:
    24 Jul 2009
    28 Dec 2009
    Link to this post
    Ok, CreateDataSource work...

    I´m in mistake with a incorrect list reference,

    Thank you very much... xDDDDD

    Salu2,
    Pablo
  12. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    28 Dec 2009
    Link to this post
    Hello xax_007,

    Always glad to help.

    All the best,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Register for webinar
12 posts, 2 answered