Executing Functions
You can execute any CMS Functions in Master Page templates.
Using Function Markup in markup files (.master)
You can use the function's markup to execute a CMS Function (similar to how you do in XSLT functions or XHTML templates).
.master
<f:function name="Composite.Navigation.Distributed" runat="server">
<f:param name="Level" value="1" />
<f:param name="ShowParent" value="False" />
<f:param name="ShowChildPages" value="True" />
<f:param name="Expand" value="False" />
<f:param name="NavigationId" value="NavigationSideBar" />
</f:function>
You can quickly insert the function markup via the menu: Insert | Function Markup.
When you manually insert the function markup, make sure to specify runat="server".
Executing CMS Functions in code files (.master.cs)
If you need to execute CMS Functions in a code file (.master.cs), make use of the FunctionFacade's methods to get the function by name (GetFunction) and execute it (Execute).
.master.cs
using System;
using Composite.Core.Xml;
using Composite.Core.PageTemplates;
using Composite.Plugins.PageTemplates.MasterPages;
using Composite.Functions;
using System.Collections.Generic;
public partial class MyPageTemplate : MasterPagePageTemplate
{
public override Guid TemplateId
{
get { return new Guid("25de2e26-ab15-4490-8501-b3e8dcb90822"); }
}
[Placeholder(Id = "content", Title = "Main Content", IsDefault = true)]
public XhtmlDocument Content { get; set; }
public XhtmlDocument distributedMenu { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
distributedMenu = FunctionFacade.Execute<XhtmlDocument>(
FunctionFacade.GetFunction("Composite.Navigation.Distributed"),
new Dictionary<string, object>() {
{ "Level", 1 }, { "ShowParent", false },
{ "ShowChildPages", true }, { "Expand", false },
{"NavigationId", "NavigationSideBar"} });
// removing the class attribute from the level menu's elements
foreach (var item in distributedMenu.Descendants())
{
item.SetAttributeValue("class", null);
}
}
} Download the sample
.master
<%@ Master Language="C#" AutoEventWireup="true"
CodeFile="UseFunctionFacade.master.cs" Inherits="MyPageTemplate" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>
<c1:Title runat="server" />
</title>
</head>
<body>
<c1:Render Markup="<%# Content %>" runat="server" />
<%= this.distributedMenu %>
</body>
</html>
Download the sample