【问题标题】:How to access current Sitecore item in layout .aspx, while in preview pane in the Sitecore content editor?如何在 Sitecore 内容编辑器的预览窗格中访问布局 .aspx 中的当前 Sitecore 项目?
【发布时间】:2023-03-23 15:26:01
【问题描述】:

我已经整理了一个 .aspx 页面,它是某个模板的布局。在 Sitecore 预览窗格中,我无法通过路径(即通过调用 Database.GetItem(string))获取当前项目,尽管它在 Web 上运行良好,即使使用 .NET Request.RawUrl 属性也是如此。

在这种情况下,我如何最轻松地访问当前项目?

【问题讨论】:

    标签: asp.net sitecore preview


    【解决方案1】:
     Sitecore.Context.Item 
    

    在预览模式和普通模式下获取当前页面的项目。

    要检查您是否处于预览状态,您可以使用:

    if (Sitecore.Context.PageMode.IsPreview) and 
    

    如果是普通页面,你可以使用:

       if (Sitecore.Context.PageMode.IsNormal )
    

    【讨论】:

    • 感谢您礼貌地回答我的新手问题。我正在尽可能快地阅读,但我正在进行一个我必须交付的项目。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多