Get the first content item on a page
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
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
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
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