Sitecore: Detect user in Page Editor mode

醉酒当歌 提交于 2019-12-23 07:49:51

问题


Can I know how to detect user is in page editor mode using code? This is because, I have a component, when user browses from page editor, it will search in master_index folder instead of web_index folder.


回答1:


Please check with : if (Sitecore.Context.PageMode.IsPageEditorEditing)

also is working on Sitecore 6.6, it not depends on Sitecore 7.

Please check also this Sitecore blog post by Martina Welander.

To check if is normal page use: if (Sitecore.Context.PageMode.IsNormal)

To check if is preview mode use: if (Sitecore.Context.PageMode.IsPreview)

Also are others PageMode:

  • IsPageEditorClassic
  • IsPageEditorDesigning
  • IsPageEditorEditing
  • IsPageEditorNavigating, etc

If you are curious you can check with Reflector or dotPeek this class: Sitecore.Context.PageMode from Sitecore.Kernel assembly.




回答2:


Rather than checking the page mode, I think you just want to piggyback on the context database name -

var indexName = Sitecore.Context.Database.Name + "_index";



回答3:


I am using this syntax in view to add a class for JS detection, same code can be used for back-end detection with bit modification:

<html class="@(Sitecore.Context.PageMode.IsPageEditor ? "inexpeditor" : "notexpeditor")">


来源:https://stackoverflow.com/questions/19961818/sitecore-detect-user-in-page-editor-mode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!