扩展组件的示例使用了注释系统,该系统实际上由两个组件组成
两个组件都需要放置到位,尤其是在自定义已发布评论的外观时。
每个网站页面只允许一个评论系统。
许多社区功能已经包括一个注释系统,其resourceType可修改为引用扩展注释系统。
这些方向指定了除.hidden
之外的组值,以便组件可以从组件浏览器(Sidekick)中使用。
删除自动创建的JSP文件是因为将改用默认的HBS文件。
浏览到CRXDE|Lite(http://localhost:4502/crx/de/index.jsp)
为自定义应用程序创建一个位置:
选择/apps
节点
选择/apps/custom
节点
选择/apps/custom/components
节点
创建>组件……
选择Next
选择Next
选择Next
选择OK
展开刚刚创建的节点:/apps/custom/components/comments
选择Save All
右键单击comments.jsp
选择Delete
选择Save All
这些方向将Group设置为.hidden
,因为页面中应仅包含父组件。
删除自动创建的JSP文件是因为将改用默认的HBS文件。
导航到/apps/custom/components/comments
节点
右键单击节点
选择创建>组件……
*.hidden*
选择Next
选择Next
选择Next
选择OK
展开刚刚创建的节点:/apps/custom/components/comments/comment
选择Save All
右键单击comment.jsp
选择Delete
选择Save All
使用CRXDE Lite:
复制 comments.hbs
将comments.hbs
编辑为:
更改data-scf-component
属性的值(~line 20):
social/commons/components/hbs/comments
/apps/custom/components/comments
修改以包含自定义注释组件(~第75行):
{{include this resourceType='social/commons/components/hbs/comments/comment'}}
{{include this resourceType='/apps/custom/components/comments/comment'}}
复制 comment.hbs
将comment.hbs
编辑为:
更改data-scf-component属性的值(~ line 19)
social/commons/components/hbs/comments/comment
/apps/custom/components/comments/comment
选择/apps/custom
节点
选择Save All
为避免明确包含此客户端库,可以使用默认注释系统的clientlib的类别值(cq.social.author.hbs.comments
),但随后,也会为默认组件的所有实例包含此clientlib。
使用CRXDE Lite:
选择/apps/custom/components/comments
节点
选择创建节点
名称: clientlibs
类型: cq:ClientLibraryFolder
添加到属性选项卡:
categories
String
NameTypeValue cq.social.author.hbs.comments
Multi
dependencies
String
NameTypeValue cq.social.scf
Multi
选择Save All
选择/apps/custom/components/comments/clientlib
s节点后,创建3个文件:
css.txt
js.txt
输入“customcommentsystem.js”作为js.txt
的内容
选择Save All
在扩展(覆盖)SCF组件时, resourceType不同(覆盖使用在/libs
之前通过/apps
搜索的相对搜索机制,以使resourceType保持相同)。 因此,必须编写JavaScript(在客户端库中)来注册SCF JS模型并查看自定义resourceType。
输入以下文本作为customcommentsystem.js
的内容:
(function($CQ, _, Backbone, SCF) {
"use strict";
var CustomComment = SCF.Components["social/commons/components/hbs/comments/comment"].Model;
var CustomCommentView = SCF.Components["social/commons/components/hbs/comments/comment"].View;
var CustomCommentSystem = SCF.Components["social/commons/components/hbs/comments"].Model;
var CustomCommentSystemView = SCF.Components["social/commons/components/hbs/comments"].View;
SCF.registerComponent('/apps/custom/components/comments/comment', CustomComment, CustomCommentView);
SCF.registerComponent('/apps/custom/components/comments', CustomCommentSystem, CustomCommentSystemView);
})($CQ, _, Backbone, SCF);
要在发布环境中体验扩展组件,需要复制自定义组件。
一种方法是
从全局导航
Activate Tree
Start Path
:至/apps/custom
Only Modified
Activate
按钮