How do I get a list of pages FluentAPI
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
Hello Gary Wedekind,
Please see the sample code below, which displays the children of Destination in a RadGrid
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'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
I use something similar to this:
SiteMapProvider provider = SiteMapBase.GetSiteMapProvider(
"FrontEndSiteMap"
);
SiteMapNode root = provider.RootNode;
SiteMapNode current = provider.CurrentNode;
how would you then display your pages on a usercontrol/page?
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.
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
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);
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
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
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
>
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();
how can I do this samething in 3.7?
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.
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.