How do I get a list of pages FluentAPI

Posted by Community Admin on 03-Aug-2018 12:46

How do I get a list of pages FluentAPI

All Replies

Posted by Community Admin on 03-Mar-2011 00:00

Hi all,
I have looked at the Fluent api but I must be missing something.
I want to be able to get a list of all pages that are Owned by a grouping page I have called "Destinations"

So I want to do something like: Get all child pages of page("destinations") and then I want to be bale to loop through the list and out put them.

Can anybody help with this.

Thanks

Posted by Community Admin on 03-Mar-2011 00:00

Hello Gary Wedekind,

Please see the sample code below, which displays the children of Destination in a RadGrid

Copy Code
           var pages = App.WorkWith()
                           .Pages()
                           .Where(p => p.Parent != null)
                           .Where(p => p.Parent.Title == "Destinations")
                           .Get()
                           .ToList();
 
           if (pages != null && pages.Count > 0)
           
               //do something
               Grid1.DataSource = pages.ToList();
               Grid1.DataBind();             
                    
           
       

I hope this information helps. if you need any further assistance, please do not hesitate to contact me.

All the best,
Boyan Barnev
the Telerik team

Posted by Community Admin on 03-Mar-2011 00:00

I'm trying to do the samething to build my custom menu, instead of binding it to a grid, can they be bound to a datalist, etc.?

I'm creating a custom nav, the one 'out of the box' just won't work for me

Posted by Community Admin on 03-Mar-2011 00:00

I use something similar to this:

SiteMapProvider provider = SiteMapBase.GetSiteMapProvider("FrontEndSiteMap");
SiteMapNode root = provider.RootNode;
SiteMapNode current = provider.CurrentNode;

You can then iterate over nodes and child nodes.  The SiteMapNode should cast to Telerik.Sitefinity.Web.PageSiteNode giving you access to sitefinity-specific properties so you can build your URLs and test whether a page should be included in the navigation.

Cheers!

Posted by Community Admin on 03-Mar-2011 00:00

how would you then display your pages on a usercontrol/page?

Posted by Community Admin on 03-Mar-2011 00:00

I created a user control then added it to my page controls in the admin area.  That gave me a widget I could drag on to my pages (Administration>settings>advanced>toolboxes>toolboxes>pagecontrols>sections>mycustomsection).  This process is fairly well documented in the SDK.  I have also found some success in customizing my CSS and templates using a navigation control.

Hope this sends you in the right direction.

Posted by Community Admin on 03-Mar-2011 00:00

I have several user controls being used within the site, yeah their easy to implement into our site and for my nav that they want, the nav control won't work so I have to create it from "scratch" and I'm just having issues getting the pages

Posted by Community Admin on 03-Mar-2011 00:00

Cool.  Here's the code that I use to render a link:

private void RenderLink(SiteMapNode node, int level, HtmlTextWriter writer)
    HyperLink link = new HyperLink();
    link.CssClass = "nav_link_level_" + level;
    link.ToolTip = node.Title;
    link.NavigateUrl = this.ResolveUrl(node.Url);
    this.RenderImageLink(node, link, writer);
    link.RenderControl(writer);

And the recursive caller:

private void RenderItem(SiteMapNode node, int level, HtmlTextWriter writer, int index)
    PageSiteNode pageNode = (PageSiteNode)node;
    if (pageNode.ShowInNavigation)
    
        if (level < (maxDepth + 1))
        
            if (!String.IsNullOrEmpty(this.ItemCssClass))
                writer.AddAttribute("class", this.ItemCssClass);
            writer.RenderBeginTag(HtmlTextWriterTag.Li);
            RenderLink(node, level, writer);
            if (node.HasChildNodes && level < maxDepth)
            
                if (!String.IsNullOrEmpty(this.LeafCssClass))
                
                    writer.AddAttribute("class", String.Format(this.LeafCssClass, index));
                
                writer.RenderBeginTag(HtmlTextWriterTag.Div);
                writer.RenderBeginTag(HtmlTextWriterTag.Ul);
                foreach (SiteMapNode child in node.ChildNodes)
                
                    RenderItem(child, level + 1, writer, index);
                
                writer.RenderEndTag(); // ul
                writer.RenderEndTag(); // div
            
            writer.RenderEndTag(); // li
        
    

As you can see, this is a very manual approach.  I took this approach so I could build the menu [n] levels deep and also because I needed to use images from an image album.  I explored binding a list of SiteMapNodes to a repeater and datalist but it turned out to be easier just rendering it on my own.

Posted by Community Admin on 04-Mar-2011 00:00

Thanks for the answers guys,
I am having to rebuild my Development Environment due to hardware issues, but I will report back soon and let you know how it worked out.

Thanks

Posted by Community Admin on 06-Apr-2011 00:00

I just had to do something very similar to this and just wanted to add a couple of thoughts.

You'll also probably want to check to make sure the page is supposed to be shown in the navigation.
Also, I think it defaults to sorting alphabetically.  If you want to use the sitemap hierarchy you'll need an OrderBy clause.
Lastly, there is no "Url" property like there is for title so you'll need to use the "GetFullUrl" function to create links.  Here's my code which binds to a repeat to create a simple UL list of links.


<%@ Import Namespace="Telerik.Sitefinity.Pages.Model" %>
<%@ Import Namespace="Telerik.Sitefinity.Modules.Pages" %>
 
 
<asp:Repeater ID="menuAbout" runat="server">
    <HeaderTemplate><ul></HeaderTemplate>
    <ItemTemplate><li><asp:HyperLink ID="hypAbout" runat="server" NavigateUrl='<%#((PageNode)Container.DataItem).GetFullUrl() %>' Text='<%#Eval("Title") %>' /></li></ItemTemplate>
    <FooterTemplate></ul></FooterTemplate>
</asp:Repeater>

and then the backend code:

using Telerik.Sitefinity;
using Telerik.Sitefinity.Pages.Model;
using Telerik.Sitefinity.GenericContent.Model;
using Telerik.Sitefinity.Modules.Pages;
 
 
        var pages = App.WorkWith()
               .Pages()
                     .ThatArePublished()
               .LocatedIn(Telerik.Sitefinity.Fluent.Pages.PageLocation.Frontend)
               .Where(p => p.Parent != null)
               .Where(p => p.Parent.Title == "About Us")
               .Where(p => p.ShowInNavigation == true)
               .OrderBy(p => p.Ordinal)
               .Get()
               .ToList();
 
        if (pages != null && pages.Count > 0)
        
            menuAbout.DataSource = pages;
            menuAbout.DataBind();
        

I like Sitefinity 4 a lot but am finding it WAY more complicated than 3.7 so I hope that helps someone else.

Note:  I updated the code above to include a "LocatedIn" clause... otherwise you'll tear your hair out trying to figure out why your pages crash when you log out of Sitefinity.

Note 2:
"Page.Status == ContentLifecycleStatus.Live" doesn't work if you have any external links in the list.  I removed it and replaced with ".ThatArePublished()" instead and that seems to do the trick.

Posted by Community Admin on 07-Apr-2011 00:00

how can I do this samething in 3.7?

Posted by Community Admin on 08-Apr-2011 00:00

Hello Mike,

Please check the following documentation article - http://www.sitefinity.com/help/developer-manual/pages-get.html
In order to filter by any of the properties page, you should first get all pages in a list, and filter this list using foreach(), and check inside of the loop the individual object properties. 

Greetings,
Georgi
the Telerik team

Posted by Community Admin on 19-Jan-2017 00:00

Hi,

      I am using Fluent Api to get List of Pages. My code snippet is 

      var pageNodes = App.WorkWith().Pages()              .LocatedIn(Telerik.Sitefinity.Fluent.Pages.PageLocation.Frontend) .Where(p => p.GetPageData() != null && p.NodeType == Telerik.Sitefinity.Pages.Model.NodeType.Standard)  .ThatArePublished() .Get().ToList();

I want to sort the retreive page nodes by LastModified parameter.

Can some one help me.

This thread is closed