Orchard Core 动手实践1

Orchard Core 源码

https://github.com/OrchardCMS/OrchardCore

1. /src/OrchardCore.Modules 文件夹中的项目并非特定于cms项目。

2. /src/OrchardCore.Modules.Cms 文件夹中的项目特定于cms

3. 引用OrchardCore.Application.Cms.Targets.dll, 该dll会把与cms相关的类库都引进项目。

image

Theme

image
  • Theme 主题,可以看做一套模板,该套模板的所定义的所有资源及配置都在xxx.recipe.json清单中。

  • Theme->Views 定义Content Type对应的Template,负责渲染特定Content Type在页面上的输出。下图是Blog Theme中的 Content Type 模板。

image

首页模板在Admin中配置,注意约定的命名格式 Content__{Content Type}. 注意Content后紧跟双下划线

image
  • Theme->Recipe , recipe 描述了该Theme所提供的所有要素和功能。前后台界面所有内容都会定义在xxx.recipe.json中。
image

上图,issetuprecipe=true, 那么就会出现在新Tenant第一次Setup配置下拉选项中。

image

在Setup页面的时候选择好recipe,配置完成后,点击创建按钮,Setup Module来执行所选recipe.

(1)steps->themes 配置说明了在Setup界面选择Agency Recipe后,管理员后台默认使用TheAdmin主题,前端默认使用TheAgencyTheme主题。

image
image
image

(2) steps->settings 配置了用那个Controller和Action来显示ContentItem

image

(3) steps->ContentDefinition 定义站点所使用的所有ContentTypes、ContentParts。如:首页面配置

image

对应后台UI

image

小结: IRecipeStepHandler 类会执行Steps中的配置。

界面

Content Items

  • 一个Content Item 可以由多个其它Content Item 组成。

新建一个Liquid界面

image

Liquid 可以访问的Site属性可以查询官方文档。

image

Queries

SQL Queries

1. SQL Queries, 点击Modules菜单,搜索框输入queries, 确保选中SQL Queries

image

2. 创建一个新的Content Type , News Item。 并添加2个News Item Content

image

点击Create

image

选中Html Body, Title, 点击Save

image

点击Save. 接下来新建News Item Content

image
点击Publis,  接着创建下一个
image

点击Publish, 完成News Item的创建。 下面是数据库Document表中存储的json,先记下来,等会SQL Query查询语句可能用得着。

image

3. 创建SQL Query, 查询new items。

参考官方文档sql query 样例。

image

创建SQL Query

image
image
image

点击Save后,出现的界面中点击Run

image

4. 在Liquid页面中运行查询。 首先参考官方文档

image

创建Liquid页面

image

Cache

1. 参考官方文档 Dynamic Cache

image

2. 在Liquid页面中加入cache块

image

Flow Page

当Page由Widget组成,则可以控制Widget在Page中的浮动。

1. 添加一个新的Page, 添加Html、Paragraph、Image 三个Widget, 内容随便填写。

image

2. 如下图,点击浮空控制栏目的选项,在Preview页面中会更改Widget的浮动位置。

image

新建一个Widget

创建一个Widget, 内容是一条分割线。

1. 新建Content Type, 命名为Section

image

2. 新建一个Template, 命名Widget__Section. 注意:必须以Widget开头

image
image

使用Widget. New->Page页面,在Widget下拉框中,就能看到该Widget

添加Tenant

1. 如果左侧的Configuration菜单中没有Tenants菜单项,要首先去Modules下启用Tenants模块。

2. 然后选中Configuration->Tenants, 添加新Tenant ,选择Blog Recipe (后面会用到), 命名evendou, 然后在Tenants列表中点击该Tenant, 会打开Setup界面。

image
image

3. Setup完成后,会在App_Data/Sites目录出现新的Tenant站点目录,这是一个资源独立的站点。打开该站点首页https://localhost:44300/evendou. 新的管理员界面https://localhost:44300/evendou/admin 区别于默认站点的管理员界面http://localhost:44300/admin

image
image

Layer

Layer 是一种显示规则,应用在Widget上,关联该Layer的Widget只有符合该Layer规则才能在Zone中显示。

image

规则配置

image

Lucence Query

进入新的Tenant(evendou)管理员后台,Configuration->Queries有Lucence示例(RecentBlogPosts), Orchard中的所有类型的查询都以REST API的方式对外提供。

image

如果以匿名用户访问Api, 首先要设置匿名用户的权限

image

然后在浏览器中输入/api/queries/RecentBlogPosts, 即可看到查询结果。

image

试试在默认站点建的SQL Query查询(记得匿名用户权限) https://localhost:44300/api/queries/allnewsitems

你可能感兴趣的:(Orchard Core 动手实践1)