我们如何为 cq5 组件添加动态路径字段(rootPath)?
有没有示例参考?
我认为您应该使用自定义小部件插件。首先,将属性添加plugins
到您pathfield
的dialog.xml
:
<myPathComponent
jcr:primaryType="cq:Widget"
fieldLabel="My path component"
plugins="customRootPathPlugin"
xtype="pathfield" />
然后创建自定义 ExtJS 插件。为此,请创建新的 JS 文件,并将其添加到带有类别的clientlib 。cq.wcm.edit
插件看起来像这样:
(function($) {
var plugin = CQ.Ext.extend(CQ.Ext.emptyFn, {
init: function(widget) {
var locale = "en";
// create some JS logic to get the locale here
// current path can be obtained via
// widget.findParentByType('dialog').responseScope.path
widget.treeRoot.name = "content/myproject/" + locale + "/mycomponent";
}
});
CQ.Ext.ComponentMgr.registerPlugin('customRootPathPlugin', plugin);
}($CQ));
为了扩展 Tomek 的答案,我能够获取当前页面,然后显示所有兄弟姐妹和孩子:
(function($) {
var plugin = CQ.Ext.extend(CQ.Ext.emptyFn, {
init : function(widget) {
var url = CQ.HTTP.getPath();
widget.treeRoot.name = url.substring(1, url.lastIndexOf('/') );
}
});
CQ.Ext.ComponentMgr.registerPlugin('customRootPathPlugin', plugin);}($CQ));
我这样做的原因是因为我最终url.substring(1
会在对话框中url.substring(0
出现双斜杠。//content/app/en/