如何动态切换SharePoint发布页面的PageLayout和MasterPage?
为了改善 SharePoint WCM 发布页面的编辑和显示体验,我希望能够在编辑模式下切换到一组特殊的母版页/页面布局。
所以在 /_catalogs/masterpage 中我想要:
MyMasterpage.master - 用于显示模式的母版页 MyMasterpage-edit.master - 编辑模式的母版页,仅在可用时使用 MyPageLayout.aspx - 显示模式的页面布局 MyPageLayout-edit.aspx - 用于编辑模式的页面布局,仅在可用时使用
当我在页面库中创建新的发布页面时,我选择 MyPageLayout 页面布局。
渲染页面时,我想检测是否处于显示编辑模式,就像服务器控件一样。 该控件执行以下代码来确定呈现模式:
private void calculateShouldRender()
{
SPControlMode contextualFormModeFromPostedForm = ConsoleUtilities.GetContextualFormModeFromPostedForm();
if ((SPControlMode.Display == contextualFormModeFromPostedForm) && (PageDisplayMode.Display == this.PageDisplayMode))
{
this.shouldRender = true;
}
else if ((SPControlMode.Edit == contextualFormModeFromPostedForm) && (PageDisplayMode.Edit == this.PageDisplayMode))
{
this.shouldRender = true;
}
else
{
this.shouldRender = false;
}
this.Visible = this.shouldRender;
}
如果呈现模式是编辑,我想切换到MyMasterpage-edit.master materpage 和MyPageLayout-edit.aspx pagelayout。
我可以在由服务器控件控制的母版页和页面布局中进行重大切换,但我想分割职责。 SharePoint 分析师可以创建最佳的编辑模式页面,前端开发人员可以创建干净漂亮的显示模式页面,而不会出现任何混乱的编辑情况。
关于如何实现这一目标有什么想法吗? 母版页切换似乎不是问题,我曾经写过 博客文章对此。 困难的事情就是页面布局的切换。
To improve both the editing and displaying experience of SharePoint WCM Publishing pages I would like to be able to switch to a special set of Masterpage/PageLayout when in edit mode.
So in /_catalogs/masterpage I want to have:
MyMasterpage.master - masterpage for display mode
MyMasterpage-edit.master - masterpage for edit mode, only use if available
MyPageLayout.aspx - pagelayout for display mode
MyPageLayout-edit.aspx - pagelayout for edit mode, only use if available
When I create a new publishing page in the Pages library, I select the MyPageLayout page layout.
When rendering the page I would like to detect if I'm in Edit of Display mode, just like the server control does. This control executes the following code to determine the render mode:
private void calculateShouldRender()
{
SPControlMode contextualFormModeFromPostedForm = ConsoleUtilities.GetContextualFormModeFromPostedForm();
if ((SPControlMode.Display == contextualFormModeFromPostedForm) && (PageDisplayMode.Display == this.PageDisplayMode))
{
this.shouldRender = true;
}
else if ((SPControlMode.Edit == contextualFormModeFromPostedForm) && (PageDisplayMode.Edit == this.PageDisplayMode))
{
this.shouldRender = true;
}
else
{
this.shouldRender = false;
}
this.Visible = this.shouldRender;
}
If the render mode is Edit, I want to switch to the MyMasterpage-edit.master materpage and the MyPageLayout-edit.aspx pagelayout.
I could make a big switch in the masterpage and pagelayout controlled by server controls, but I would like to split resposibilities. A SharePoint Analist can create optimal edit mode pages, and a front end developer can create clean and beautiful display mode pages without all the editing clutter.
Any ideas on how to accomplish this? Masterpage switching does not seem the problem, I once wrote a blogpost on this. The difficult thing seems the switching of the page layout.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我认为,如果您继续沿着这条路线走下去,您将会与 SharePoint 作斗争,我担心它也会成为一场支持噩梦,因为问题所在变得不太清楚,或者记住在出现问题时在两个(或全部四个!)地方进行更改已更新。
您可以根据页面的编辑模式显示或隐藏控件,因此向用户显示的内容完全不同,但页面的所有代码仍然位于一个位置。
研究编辑模式面板。
我意识到这并不完全是您所要求的...但我发现与 SharePoint 的战斗是一场失败的战斗,您只需要按照它的“方式”工作即可。
I think you would be fighting SharePoint if you continue down that route, I fear it would also become something of a support nightmare as it becomes less clear where problems lie, or remembering to make changes in both (or all four!) places when something is updated.
You can have controls appear or hide depending on the editmode of a page so what is shown to the user is totally different but all the code for a page is still in one place.
Investigate the editmodepanel.
I realise that is not quite what you asked... but I find fighting SharePoint is a losing battle you just have to work with its 'way'.
我曾经编写过一个功能来根据不同的条件切换页面布局。 不同之处在于,页面布局是在网站创建期间更改的,而不是在查看或编辑模式下更改的。 更改页面布局的代码如下:
I once wrote a feature to switch page-layouts depending on different criteria. The difference was, that the page-layout was changed during site-creation, not in view or edit mode. The code to change the page-layout is as follows:
我的文字对于评论框来说太长了,所以我在 Aiden 上回答,就好像它是一个答案一样,但我的问题仍然存在!
您好,Aidan,我将 SharePoint 视为一个可以在其上构建解决方案的平台。 而且我认为微软在该平台之上构建的WCM解决方案很弱。 我知道我的方法不是直接的SharePoint标准方法,但标准方法就是行不通。 结合编辑和显示模式会导致(选择您的选择):
- 标准 SharePoint 发布网站,看起来都很相似,但在编辑模式下工作正常
- 一个非常可编辑但外观非常基本的网站
- 一个在显示模式下看起来很漂亮的网站,几乎无法编辑
显示模式所需的样式表与 MOSS WCM 样式表之间存在很多冲突。 我们确实编写了各种补偿样式表以使其正常工作,但这确实很痛苦。 在页面中注入带有样式的代码以使编辑成为可能是一个主要缺陷,这应该完全在您正在编辑的页面之外完成。 例如,在 iframe 中,它可以在您正在编辑的页面顶部显示为浮动窗口。 但这种情况并非如此。 然后我什至没有提到当您的页面上有选项卡或手风琴控件时遇到的问题。
我们的目标是真正交互式的 Web 2.0 网站,其中必须进行大量内容管理。 以 SharePoint 方式获得正确的编辑模式是行不通的。
最佳的编辑体验是关键。 那么为什么不使用针对编辑进行优化的母版页和页面布局,以便以清晰一致的方式访问所有可编辑元素。 但你仍然需要显示模式。 这可以使用一个完全独立的网站来完成,该网站仅使用 SharePoint 中生成的数据。 这可以是 ASP.NET 站点,或者如果您想完全控制 html MVC,则可以使用。 我不打算这样做,因为但是在导航、安全性、控件重用、Web 部件的使用等方面有很多影响。
我认为如果使用优化的母版页/页面布局,您将获得两全其美的效果用于编辑,另一对母版页/页面布局仅用于在页面布局中使用最少的代码集进行显示。
所以..请继续提供答案!
My text was too long for the comment box, so I answer on Aiden as if it is an answer, but my question remains!
Hi Aidan, I see SharePoint as a platform where you can build your solutions on. And I think that the WCM solution built by Microsoft on top of the platform is weak. I know my way is not directly the SharePoint standard way, but the standard way just does not work. Combining edit and display mode leads to (pick your choice):
- standard SharePoint publishing sites that all look alike but work ok in edit mode
- a site that is very editable but very basic in its appearance
- a great looking site in display mode, that is almost impossible to edit
We have a lot of clashes between the stylesheets needed in display mode with the MOSS WCM stylesheet. We did write all kinds of compensating stylesheets to get it working, but it is a pain in the ***. It is a major flaw to inject code with styles in your page to make editing possible, this should have done completely outside the page you are editing. In an iframe for example which can be displayed as a floating window on top of the page you are editing. But this is not the case. And then I didn't even mention the issues you have when you have tabs or an accordion control on your page.
We are targeting really interactive web 2.0 sites where a lot of content management must be done. Getting editing mode right in the SharePoint way just does not work.
An optimal editing experience is key. So why not use the masterpage and pagelayout optimized for editing so all editable elements are reachable in a clear and consistent way. But then you still need the display mode. This could be done using a complete separate site that just uses the data produced in SharePoint. This can be an ASP.NET site, or if you want full control over the html MVC could be used. I don't at to go that way, because but has a lot of implications in navigation, security, reuse of controls, use of web parts etc.
I think you get best of both worlds if a masterpage/pagelayout is used that is optimized for editing, and another couple of masterpage/pagelayout is used for display only with a minimal set of code in the pagelayout.
So.. keep the answers coming please!
当然,这需要子类化 Microsoft.SharePoint.Publishing.PublishingLayoutPage 并使用它来呈现根据“编辑模式”所需的实际 PublishingLayoutPage 的内容。
如何更改母版页...ek。
Surely that would require subclassing Microsoft.SharePoint.Publishing.PublishingLayoutPage and use that to render the contents of the actual PublishingLayoutPage required depending on the "edit mode".
How to get a master page changed...ek.
再次尝试让 SharePoint 屈服于您的意志吗? ;)
我感受到你的痛苦。 我使用两种方法来获得类似的行为:
有条件地渲染页面部分的容器控件,我认为就像您所建议的那样。 最初,当某些字段具有特定值时,我需要它隐藏页面的部分内容,因此不会呈现 html。 请参阅包装控件。
控件本身非常简单,它的类上需要一个 [ParseChildren(false)],并且如果不满足条件,渲染方法不会调用基本渲染。
您可以扩展它以向编辑器和设计器显示完全不同的页面,尽管它们仍然位于同一页面中。 我想你可以去掉分析仪使用的部分并将其放入自己的用户控件中,但这不太可维护。
其次,表单页面(例如“/Pages/Forms/EditForm.aspx?ID=1”)提供了发布页面上所有字段的清晰视图。没有任何设计妨碍。 (我在所有页面布局上使用一个控件,该控件提供对此页面库和当前页面库的一键访问,并显示所使用的内容类型和页面布局。在构建 WCM 站点时非常有用。)
Trying to bend The SharePoint to your will again? ;)
I feel your pain. I'm using 2 ways to get similar behaviour:
A container control to condionally render parts of pages, I think like you suggested. Initially I needed it to hide parts of the page when some field had a specific value so no html was rendered. See wrapper controls.
The control itself is very simple, it needs a [ParseChildren(false)] on its class and the render method does not call the base render if the condition is not met.
You can extend this to display en entirely different page to an editor and designer although it would all still live in the same page. I guess you could strip out the part used by the analist and put it in its own usercontrol but thats not very maintainable.
Secondly, the form page, e.g. "/Pages/Forms/EditForm.aspx?ID=1", gives a clean view of all the fields on a publishing page.. no design to get in the way. (I use a control on all page layouts that provides 1 click access to this and the current pages library and shows the content type and page layout used. Quite useful when building WCM sites.)
这个问题的明确答案现在已“烘焙”到我们称为 DualLayout for SharePoint 的产品中! 我们的方法解决了您所有的 SharePoint WCM 设计噩梦:
请访问 http://www.macaw.nl 查看/Het+Bedrijf/Producten/Macaw+DualLayout+for+SharePoint.aspx,请参阅该页面博客卷中的博客文章,了解详细的背景信息。
The definitive answer to this question is now "baked" into a product which we call DualLayout for SharePoint! Our approach solves all your SharePoint WCM design nightmare:
Check it out at http://www.macaw.nl/Het+Bedrijf/Producten/Macaw+DualLayout+for+SharePoint.aspx, see the blog posts in the blog roll of that page for detailed background information.