Add dynamic pathfield(rootPath) for cq5 component

故事扮演 提交于 2019-11-28 11:49:35

I think you should use custom widget plugin. First, add property plugins to your pathfield in the dialog.xml:

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

Then create custom ExtJS plugin. In order to do that, create new JS file, and add it to clientlib with cq.wcm.edit category. Plugin can look like that:

(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));

To expand on Tomek's answer, I was able to get the current page and then display all the siblings and children with this:

(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));

The reason I did url.substring(1 instead of url.substring(0 is because I would end up with double forward slash //content/app/en/ in the dialog.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!