【问题标题】:Add dynamic pathfield(rootPath) for cq5 component为 cq5 组件添加动态路径字段(rootPath)
【发布时间】:2013-09-26 13:17:35
【问题描述】:

我们如何为 cq5 组件添加动态路径字段(rootPath)?

有没有示例参考?

【问题讨论】:

  • 你能再写点什么吗? rootPath 应该是动态的是什么意思?应该如何获得?
  • 示例:rootPath 值 /content/myproject/locale/mycomponent/pages 在这里我想根据我的页面特定语言环境信息动态添加“语言环境”信息(如 en/fr/ar/etc ..) 所以 rootPath 值应该显示为 For a English page /content/myproject/en/mycomponent/ For French /content/myproject/fr/mycomponent/ For Arabic /content/myproject/ar/mycomponent/ etc..跨度>

标签: aem


【解决方案1】:

我认为您应该使用自定义小部件插件。首先,将属性plugins 添加到dialog.xml 中的pathfield

<myPathComponent
    jcr:primaryType="cq:Widget"
    fieldLabel="My path component"
    plugins="customRootPathPlugin"
    xtype="pathfield" />

然后创建自定义 ExtJS 插件。为此,创建新的 JS 文件,并将其添加到 clientlibcq.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));

【讨论】:

  • 你能显示dialog.xml的完整代码吗?我有问题)
  • 感谢您的解决方案。但我正在尝试使用 xtype "paragraphreference" 来实现这一点。当我使用段落引用时,我没有将 widget.treeRoot 设置为“未定义”。
【解决方案2】:

为了扩展 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/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-11-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-21
    • 1970-01-01
    • 2018-03-08
    相关资源
    最近更新 更多