作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使我的 Sitecore 网站与页面编辑器兼容,即所有字段文本、富文本编辑器等都应该能够在页面编辑器中更新。
到目前为止,我已经修改了 TDS T4 模板,它为每个字段返回一个 HTMLString
,如下所示:
public HtmlString HeroImageField(bool isEditable = true, string parameters = "")
{
string renderParameter = GenerateRenderParameter(isEditable, parameters);
return new HtmlString(Sitecore.Web.UI.WebControls.FieldRenderer.Render(
Sitecore.Context.Database.GetItem(this.EntityId.ToString()), "Hero Image", renderParameter ));
}
因此,在 View 中我只需调用 Model.HeroImage()
有没有更好的方法来实现上述目标?也许 Glass Mapper 对此提供了开箱即用的支持(我不知道)。
最佳答案
Sitecore 附带 MVC 帮助程序,您可以使用它们使字段可编辑:
@Html.Sitecore().Field("My Field Name") //Context item by default
@Html.Sitecore().Field("My Field Name", Model.PageItem) //Explicit page item
@Html.Sitecore().Field("My Field Name", Model.Item) //Datasource item (may be context item)
我的建议也是使用 Controller 加载不同的 View 进行编辑。创作领域通常需要不同的视觉效果。轮播/选项卡应该展平,验证消息需要公开,等等。
查看更多信息: http://sitecore-community.github.io/docs/sitecore-mvc/rendering-content/
关于Sitecore 8 MVC : How to make the field editable in Page Editor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33145431/
我是一名优秀的程序员,十分优秀!