如何在 Orchard 1.9 中创建布局元素 [英] How to create layout elements in Orchard 1.9

查看:40
本文介绍了如何在 Orchard 1.9 中创建布局元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以指导我如何在 Orchard 1.9 中创建布局元素.我在网上找不到任何资源.

Can someone please guide me on how to create layout elements in Orchard 1.9. I couldn't find any resource online.

推荐答案

一般来说,创建一个新的布局元素类似于创建一个新的部件.这个过程涉及一个驱动程序和一些视图.重点 - 您需要实现如下:

In general, creating a new layout element is similar to creating a new part. There is a driver and a few views involved in the process. To the point - you need to implement as follows:

  • 元素类..继承自 Element 的类,包含所有元素数据.可以说是模型.
  • 驱动程序. 继承自 ElementDriver 的类,其中 TElement 是您在上面创建的类型.每个元素都有自己的驱动程序,用于处理显示管理编辑器(和回发)和前端显示视图.
  • 形状.按照惯例,所有形状都应放在 /Views/Elements/ 文件夹下.

  • An element class.. Class that inherits from Element, which contains all the element data. A model, so to speak.
  • A driver. Class that inherits from ElementDriver<TElement>, where TElement is the type you created above. Each element has it's own driver that handles displaying admin editor (and the postback) and frontend display views.
  • Shapes. All shapes should be placed under /Views/Elements/ folder, by convention.

  • 显示形状. 以您的元素命名,即.MyElement.cshtml.这个在前端呈现您的元素.
  • 设计显示形状..以您的元素命名,带有 .Design 后缀,即.MyElement.Design.cshtml.这将在布局编辑器中呈现您的元素.
  • 编辑器形状..这个应该放在/Views/EditorTemplates/ 文件夹中.默认命名约定是 Elements.MyElement.cshtml.当您在布局编辑器画布上放置新元素时,它会呈现显示的编辑器.
  • Display shape. Named after your element, ie. MyElement.cshtml. This one renders your element on frontend.
  • Design display shape.. Named after your element, with .Design suffix, ie. MyElement.Design.cshtml. This one renders your element inside the layout editor.
  • Editor shape.. This one should be put in /Views/EditorTemplates/ folder instead. Default naming convention is Elements.MyElement.cshtml. It renders the editor shown when you drop a new element on layout editor canvas.

完成上述所有操作后,您的新元素应该出现在布局编辑器右侧的元素列表中,可以使用了.

With all above done, your new element should appear in the list of elements on the right side of the layout editor, ready to use.

如果你想做一些更复杂的元素,请检查现有的实现.Layouts 模块有一个非常不错的架构,所以你应该很快就能上手.请记住我上面写的必要步骤.

If you want to do some more complex elements, please check the existing implementations. Layouts module has a very decent architecture so you should get up to speed pretty quickly. Just keep in mind the necessary steps I wrote above.

这篇关于如何在 Orchard 1.9 中创建布局元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆