I just recently needed to add in the default audience field control to a publishing page layout. So that when you edit the page you can easily specify the target audience for the page without having to go to “Edit Properties” in the ribbon. The only issue is that it is not as simple as you would think. In my previous post I provided detail on how to Hide SP 2010 Page Layout Metadata – WebControls however the “Audience” field control requires some additional references to the Microsoft.Office.Server.UserProfiles field types.
I found this blog here: Showing the Audience Target field in an EditModePanel #SharePoint #SP2010 #in #ProjectServer #PS2010 that really helped with solving my problem.
So basically to add in the audience field control to the page in edit mode you would simply have to do the following within your custom page layout.
- Add in the following to the reference section near the top of your page layout.
<%@ Register TagPrefix="OfficeWebControls" Namespace="Microsoft.Office.Server.WebControls.FieldTypes" Assembly="Microsoft.Office.Server.UserProfiles, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> - Then add in the following code within the edit mode panel control.
<OfficeWebControls:SPFieldTargetToControl ID="Audience" runat="server" FieldName="Audience" />
If you do not already have a hidden menu control on the page you can simply add the following:
<PublishingWebControls:editmodepanel runat="server" id="editmodepanel1">
<OfficeWebControls:SPFieldTargetToControl ID="Audience" runat="server" FieldName="Audience" />
</PublishingWebControls:editmodepanel>
Thanks Giles Hamson for your post!
Comments