Get the first content item on a page

Posted by Community Admin on 04-Aug-2018 19:46

Get the first content item on a page

All Replies

Posted by Community Admin on 09-Aug-2011 00:00

Hi there, I need to write out the first few sentences of a given page as there is no descriptive field in the properties of a page that I can utilise. So it will be the first 'content block' that they add to that page (there will be at least one per page), and the first few characters from that content block. Is this possible using Page.Controls? Even so how do I know its the top content block they add (the first one at the top of the page is the one I want to grab)?

thanks, Louise

Posted by Community Admin on 10-Aug-2011 00:00

Hello Louiseba,

Here is a sample code that illustrates how to get the fist control

var pages = App.WorkWith().Pages().LocatedIn(Telerik.Sitefinity.Fluent.Pages.PageLocation.Frontend)
            .Where(p => p.Page != null&&
                        p.Page.Controls.Where(c => c.ObjectType.StartsWith(typeof(ContentBlock).FullName)).Count() > 0)
            .Get().ToList();
// get the controls from each page
            foreach(var tnp in pages)
           
                var block = (from a intnp.Page.Controls.Where(p => p.ObjectType.StartsWith(typeof(ContentBlock).FullName)) select a).FirstOrDefault();
               var c = man.LoadControl(block) ContentBlock;


All the best,
Ivan Dimitrov
the Telerik team

Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 10-Aug-2011 00:00

Thanks, but what is 'man'??

(actually i worked that bit out .. pagemanager !)

And could you point me in the direction of how to then get the content that the user has added to the content block?

thanks, Louise

Posted by Community Admin on 10-Aug-2011 00:00

Hello Louiseba,

Use the public properties of the ContentBlock

www.sitefinity.com/.../properties_t_telerik_sitefinity_modules_genericcontent_web_ui_contentblock.html

All the best,
Ivan Dimitrov
the Telerik team

Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

This thread is closed