We had a requirement wherein we wanted to create a SharePoint menu with 4 level
of menus. We used an xml source for the same for the same.
Step1: Create a document library and add a new xml document from SharePoint designer.
Step 2: Open your master page and add a new datasource. To add a new datasource, click on the above ribbon and select DataSource - select your xml file. It will include the below code in your master page
'SharePoint:SPXmlDataSource runat="server" id="SPXmlDataSource1"' 'DataFileParameters' 'asp:Parameter Name="FileName" DefaultValue="main_menu.xml"/' 'asp:Parameter Name="FilePath" DefaultValue="Menu"/' '/DataFileParameters' '/SharePoint:SPXmlDataSource'
Step 3: Make the below changes in your AspMenu control:
'SharePoint:AspMenu
ID="SPSiteMapProvider1"
Runat="server"
EnableViewState="false"
DataSourceID="SPXmlDataSource1"
UseSimpleRendering="true"
UseSeparateCss="false"
Orientation="Horizontal"
StaticDisplayLevels="2"
MaximumDynamicDisplayLevels="4"
SkipLinkText=""
CssClass="Custom-tn"'
'DataBindings'
'asp:menuitembinding NavigateUrlField="url"
TextField="text" /' '/DataBindings'
'/SharePoint:AspMenu'
Notice two things above - DataSourceID is the same as the XML datasource.
Also, we have included something as DataBindings to get the exact value from the xml. This is going to change depending on the text field in the xml you are using.
In case you need the same setting for your sub sites as well, you will need to create another master page. Simply copy everything in your master page, create a new one and make the below change.
Step1: Create a document library and add a new xml document from SharePoint designer.
Step 2: Open your master page and add a new datasource. To add a new datasource, click on the above ribbon and select DataSource - select your xml file. It will include the below code in your master page
'SharePoint:SPXmlDataSource runat="server" id="SPXmlDataSource1"' 'DataFileParameters' 'asp:Parameter Name="FileName" DefaultValue="main_menu.xml"/' 'asp:Parameter Name="FilePath" DefaultValue="Menu"/' '/DataFileParameters' '/SharePoint:SPXmlDataSource'
Step 3: Make the below changes in your AspMenu control:
'SharePoint:AspMenu
ID="SPSiteMapProvider1"
Runat="server"
EnableViewState="false"
DataSourceID="SPXmlDataSource1"
UseSimpleRendering="true"
UseSeparateCss="false"
Orientation="Horizontal"
StaticDisplayLevels="2"
MaximumDynamicDisplayLevels="4"
SkipLinkText=""
CssClass="Custom-tn"'
'DataBindings'
'asp:menuitembinding NavigateUrlField="url"
TextField="text" /' '/DataBindings'
'/SharePoint:AspMenu'
Notice two things above - DataSourceID is the same as the XML datasource.
Also, we have included something as DataBindings to get the exact value from the xml. This is going to change depending on the text field in the xml you are using.
In case you need the same setting for your sub sites as well, you will need to create another master page. Simply copy everything in your master page, create a new one and make the below change.
No comments:
Post a Comment