Quantcast
Channel: Sitefinity – Falafel Software Blog
Viewing all articles
Browse latest Browse all 73

Sitefinity: Page Selector Field for Multisite

$
0
0

Multisite is a great feature in the Sitefinity, which helps you centrally manage multiple sites using one administration panel. Few days ago I was working in a same environment where I needed to add a Page Selector field to a custom module built using Module Builder. But we needed to make Page Selector field to show pages from the current site. As it takes a rootNodeId (GUID for root page node) so it shows same pages under provided id. So, we needed to make it dynamic so that it would load pages from the current site.

Note that we don’t have access to change the behavior of Telerik.Sitefinity.Web.UI.Fields.PageField. So, I wrapped it in a custom field control and called it PageFieldControlSelector. This way I had the liberty to allow PageField control not to bind on load because it retrieves the page hierarchy before it is shown.

<%@ Control Language="C#" AutoEventWireup="true" %>
<%@ Register Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Web.UI" TagPrefix="sf" %>
<%@ Register Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Web.UI.Fields" TagPrefix="sf" %>
<%@ Register Assembly="Telerik.Sitefinity" TagPrefix="designers" Namespace="Telerik.Sitefinity.Web.UI.ControlDesign" %>
<sf:ResourceLinks ID="resourcesLinks" runat="server">
    <sf:ResourceFile JavaScriptLibrary="JQuery" />
    <sf:ResourceFile Name="Styles/jQuery/jquery.ui.core.css" />
    <sf:ResourceFile Name="Styles/jQuery/jquery.ui.dialog.css" />
    <sf:ResourceFile Name="Styles/jQuery/jquery.ui.theme.sitefinity.css" />
</sf:ResourceLinks>

<sf:SitefinityLabel ID="titleLabel" runat="server" CssClass="sfTxtLbl" />
<sf:PageField ID="PageSelector" runat="server" WebServiceUrl="~/Sitefinity/Services/Pages/PagesService.svc/" DisplayMode="Write" />
<sf:SitefinityLabel ID="descriptionLabel" runat="server" WrapperTagName="div" HideIfNoText="true" CssClass="sfDescription" />
<sf:SitefinityLabel ID="exampleLabel" runat="server" WrapperTagName="div" HideIfNoText="true" CssClass="sfExample" />

In the InitializeControls method, I set the Page Selector root node Id and forced it not to bind on load.

protected override void InitializeControls(GenericContainer container)
{
    this.TitleLabel.Text = this.Title;
    this.DescriptionLabel.Text = this.Description;
    this.ExampleLabel.Text = this.Example;

    this.PageSelector.RootNodeID = SiteInitializer.CurrentFrontendRootNodeId;
    this.PageSelector.WebServiceUrl = "~/Sitefinity/Services/Pages/PagesService.svc/";
    this.PageSelector.BindOnLoad = false;
}

This helps helps Page Selector to figure out the current site context and loads the appropriate pages. You can download the source code from here and add it as a text field with type SitefinityWebApp.Fields.PageFieldControlSelector.

Page Selector

Page Selector

Cheers!

The post Sitefinity: Page Selector Field for Multisite appeared first on Falafel Software Blog.


Viewing all articles
Browse latest Browse all 73

Trending Articles