开发者

Sharepoint: Hide fields from publishing page

I have a page layout that intherits from PublishingLayoutPage. In it there is specified a number of fields - the content can be seen here: http://pastebin.com/L4fmc3qb.

However, two of the fields (SendSMS and SendEmail) I only want shown on the edit form on the page, not when it is 开发者_如何学运维viewed as a page. How do I hide these fields on the shown page?

Alternatively, is there any way to "inject" these two fields into the page and catch them with an item event? Currently, these fields have been added to the content type that the page makes use of and I use an item event receiver to see if they have been checked, but if there is an alternate way to do this that's fine as well.


In Sharepoint 2010 you can do this with regular CSS (I'm sure it also works with 2007, but I don't have a system to test on now) - or check the second part of the answer.

You first have to load a special CSS file for when you are in Edit mode:

<PublishingWebControls:EditModePanel runat="server" id="editmodestyles">
        <!-- Styles for edit mode only-->
        <SharePoint:CssRegistration name="<% $SPUrl:~sitecollection/Style Library/~language/Core Styles/edit-mode.css %>"
            After="<% $SPUrl:~sitecollection/Style Library/~language/Core Styles/normal.css %>" runat="server"/>
    </PublishingWebControls:EditModePanel>

If you now have the class e.g. hideMeFromPage you could add that to your normal.css:

.hideMeFromPage {
    display:none;
}

In your edit-mode.css you can now overwrite this property like so:

.hideMeFromPage {
    display:block !important; //important, just to make sure even though it is loaded after the original declaration ;-)
}

You only have to add that style to your <div class="byline hideMeFromPage"> and attach a custom edit CSS and you are good to go.


Edit: Stupid me... Of course you can also just put your fields within the EditModePanel tags as described on MSDN or a very nice example page with more kinks about page layouts:

Where the previous control examined the user's permissions to establish whether content should be shown, the EditModePanel looks at whether the current page is in display or edit mode. This can be incredibly useful in the WCM world for displaying help messages or other content to users as they edit a page. However there are other uses - hiding navigation, adding inline CSS override classes to use different formatting (particularly useful) and emitting debug information in the HTML output are all examples. via Great Controls to be aware of when building Sharepoint sites

Example usage:

<PublishingWebControls:EditModePanel SuppressTag="false" GroupingText="Title help" PageDisplayMode="Edit" runat="server" id="EditModePanel1">
    ~~Your fields go in here~~
</PublishingWebControls:EditModePanel>


This is generally done by simply removing the field from the controls on the page layout in sharepoint designer or your custom page layout definition. The field definition is actually part of the content type so if someone were to edit the page properties they should see the field defined. But removing it from the page fields on the page layout itself takes it away from the rendering.


edit: Completely forgot about the EditModePanel control

http://www.andrewconnell.com/blog/archive/2006/12/23/5535.aspx


You can limit any content to be displayed only on edit mode using the tag:

    <PublishingWebControls:EditModePanel runat="server">


put your <SharePointWebControls> tag in between <PublishingWebControls:EditModePanel> will do

example

<PublishingWebControls:EditModePanel runat="server">
        <SharePointWebControls:FieldProperty FieldName="Article Expired Date" PropertyName="Description" runat="server" />
</PublishingWebControls:EditModePanel>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜