【问题标题】:Accessing "customconfiguration" inside GUI Extension在 GUI 扩展中访问“自定义配置”
【发布时间】:2012-11-08 10:02:51
【问题描述】:

我正在通过覆盖其中一个 javascript 文件的行为来对用户界面 (SiteEdit) 进行 GUI 扩展,以添加一些功能。 javascript 文件是 "/Scripts/Components/ExtComponentField.js",目标是 "SiteEdit" 扩展:

Tridion.Web.UI.Editors.SiteEdit.Views.Content

所有的扩展都可以很好地工作,我有我想要的,但现在我正在尝试使用

设置/自定义配置/客户端配置

扩展配置的节点,使用一些初始化参数,但是在javascript中无法访问$config元素,Tridion.Core.Configuration.Editors["myExt "].configuration 为空。

我已经看到在“仪表板”或“足迹”等各种 javascript 中使用此自定义配置,但是否可以在“内容”上使用它?我在扩展配置上遗漏了什么吗?

【问题讨论】:

    标签: tridion tridion-2011


    【解决方案1】:

    恐怕我没有对此进行测试,但您应该可以使用:

    Extensions.YourExt.getConfigurationItem = function (itemName, editorName)
    {
        var editor = $config.Editors[editorName].configuration;
        if (editor)
        {
            var confXml = $xml.getNewXmlDocument(editor);
            var confObj = $xml.toJson(confXml);
    
            if (confObj[itemName])
                return confObj[itemName];
            else
                return "";
        }
    }
    

    然后您可以通过以下方式使用它:

    $this.getConfigurationItem("YOUR_CONFIG_ITEM_NAME", "YOUR_EDITOR_NAME").toString();
    

    在您的扩展配置中(<theme> 节点下方)您可以输入自己的配置值:

    <customconfiguration>
      <clientconfiguration xmlns="http://www.sdltridion.com/2009/GUI/Configuration/Merge">
      <YOUR_CONFIG_ITEM_NAME>The value</YOUR_CONFIG_ITEM_NAME>
    

    你能确认一下吗:)

    【讨论】:

    • 这正是我尝试使用自定义配置的方式,但没有 $config 对象,并且 Tridion.Core.Configuration.Editors["myExt"].configuration 为空
    • 谢谢约翰,当 javascript 加载到配置可用的块中时,您的状态是可以的。在这种情况下,.js 位于“内容”块中,并且没有配置。 blocks 我的意思是加载 javascript 的组,如 Bootstrap、Views、Editor 等。我认为必须有一种方法可以通过添加一些 来将此配置包含在 Content 组中扩展配置中的依赖项
    【解决方案2】:

    我通常使用一个单独的 JS 文件,内容如下:

    Type.registerNamespace("Extensions.Namespace");
    
    Extensions.Namespace.getEditorConfigSection = function Editor$getEditorConfigSection() {
        if (this._settings === undefined) {
            var editor = $config.Editors["ThisEditorName"];
            if (editor && editor.configuration && !String.isNullOrEmpty(editor.configuration)) {
                var configSectionXmlDoc = $xml.getNewXmlDocument(editor.configuration);
                this._settings = $xml.toJson(configSectionXmlDoc.documentElement);
            }
        }
        return this._settings;
    };
    

    并在配置中将其添加到单独的组中:

    <cfg:group name="Extensions.Namespace" merge="always">
        <cfg:fileset>
            <cfg:file type="script">/Scripts/Definitions.js</cfg:file>
        </cfg:fileset>
    </cfg:group>
    

    然后在需要的地方,可以添加如下依赖:

    <cfg:dependency>Extensions.Namespace</cfg:dependency>
    

    那我一般用这样的函数来获取某个配置值:

    Extensions.Namespace.Something.prototype._getMyConfigValue = function Something$_getMyConfigValue() {
        var configSection = Extensions.Namespace.getEditorConfigSection();
        if (configSection) {
            return configSection.myconfigvalue;
        }
    };
    

    【讨论】:

    • 谢谢 Bart,同样的事情,$config 在 .../WebUI/Editors/SiteEdit/Views/Content_v6.1.0.55920.29_.aspx?mode= 中不可用js 加载扩展代码的地方。我正在扩展目标 Tridion.Web.UI.Editors.SiteEdit.Views.Content ,似乎在这种情况下,配置对象没有加载。可能是依赖关系的问题。
    【解决方案3】:

    “内容”组中包含的代码在托管您发布的网页的 IFRAME 内运行。可以想象,其中包含的文件数量应该被最小化,因此很多功能不可用。

    我的建议是仅在主窗口中读取配置,然后将所需的设置传递给在 IFRAME 中运行的代码——通过使用 Tridion.Utils.CrossDomainMessaging 实用程序类 ($xdm) .

    【讨论】:

      猜你喜欢
      • 2020-02-29
      • 2019-12-07
      • 1970-01-01
      • 2019-08-24
      • 1970-01-01
      • 2012-09-27
      • 2014-05-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多