2

On a branding website, I placed header and footer in the master page. Then I created the layout for welcome page and another for sub-sites. Now, the footer in main page has an extra row (a div nested inside the footer) for search-bar, but the sub-sites won't have the search field there.

Having said that, what would be the best way to handle it.

  • Should I create a separate master-page for sub-sites excluding the search row?

  • [untidy way] Should I put the opening tag and the search-row in the layout of welcome page and just the opening tag in the sub-site's layout (while keeping the rest of footer in master-page)?

  • Should I place a condition in master page, something like:
    <% if((new SiteTools()).getLayout(Request) == "WelcomeLayout") %>
    (by turning safe mode parser off -- bad idea that is)?

Or is there anything like SSI or render-partial in SharePoint?

Please suggest the better approach.

Update

This is the nested HTML inside the footer, which should only appear on the Home page:

<div class="search_wrapper">
    <div class="search_area">
        <div class="search_catrgories">
            <select class="categories_selection">
                <option value="1">All Categories</option>
                <option value="2">Product</option>
                <option value="3">Safety Data</option>
            </select>
        </div>
        <div class="search_fields">
            <asp:ContentPlaceHolder ID="PlaceHolderSearchArea" runat="server">
                <SharePoint:DelegateControl runat="server" ControlId="SmallSearchInputBox"
                     Version="4" />
            </asp:ContentPlaceHolder>
        </div>
    </div>
</div>

2 Answers 2

2

I'd rather avoid multiple masterpages and turning off the safe mode parser. Instead give your DIV an id and use simple CSS to hide it:

<div id="idFooter">your footer goes here</div>

Then add the below CSS to the subsite welcome page layout.

<style type="text/css">
#idFooter {display: none;}
</style>

If you want to avoid changing each subsite welcome page layout, just reverse the logic like this:

<div id="idFooter" style="display: none;">your footer goes here</div>

And put the following into your main welcome page layout:

<style type="text/css">
#idFooter {display: block;}
</style>

Since the CSS is only required on the main page all your subsites stay untouched and it is easier to maintain a single masterpage and page layout.

1
  • +1. CSS made it so striaghtforward and easy. I am more interested in learning @PerJakobsen's way :-) Thanks for your input! Commented Sep 3, 2012 at 4:11
2

The "SharePoint" way to do this is to:

  • insert an empty <Delegate> control in the Master page
  • create a User control with the search bar
  • create a Web scoped feature with a <Control> element inserting the User control in the delegate control
  • activate that feature only on the root site

See Delegate Control

So to match your updated question you should change the master page to contain something like:

<SharePoint:DelegateControl runat="server" ControlId="MySearchBar" Version="4" />
<asp:Panel runat="server" Visible="false">
  <asp:ContentPlaceHolder id="PlaceHolderSearchArea" runat="server">
  </asp:ContentPlaceHolder>
</asp:Panel>

Your UserControl should contain something like:

<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="MySearchBar.ascx.cs" Inherits="NestedDelegates.ControlTemplates.NestedDelegates.MySearchBar" %>
<div class="search_wrapper">     
  <div class="search_area">     
    <div class="search_catrgories">     
      <select class="categories_selection">     
          <option value="1">All Categories</option>     
          <option value="2">Product</option>     
          <option value="3">Safety Data</option>     
      </select>     
    </div>     
    <div class="search_fields">     
       <SharePoint:DelegateControl runat="server" ControlId="SmallSearchInputBox" Version="4" />     
    </div>     
  </div>     
</div>  

And the elements.xml in the feature should contain:

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Control Id="MySearchBar" Sequence="10" ControlSrc="~/_controltemplates/NestedDelegates/MySearchBar.ascx" />
</Elements>
2
  • +1, thanks for the input. But I already have a delegate control inside the footer for search bar. Please take a look at the Update section of my original post. Can you please explain how to digest the entire block in a User control and activate the feature. I am new to SharePoint publishing sites. A little explicit steps would be brilliant! :-) Commented Sep 3, 2012 at 4:08
  • This approach will not do what the OP want because it will hide the complete footer and not only the search field. The DIV with the search field needs to be wrapped into its own feature and activated on the main page only.
    – Sig Weber
    Commented Sep 3, 2012 at 11:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.