【问题标题】:Drupal Theme Sanitized PathDrupal 主题清理路径
【发布时间】:2016-08-20 11:33:39
【问题描述】:

我有一个自定义的 Drupal 主题 Starterkit。其中有一个 JS 文件,我需要在其中获取当前主题的路径。示例:

imagesPath: '/sites/default/themes/{{ THEME SANITIZED }}/js/ckeditor_templates/',

因为有可能有人会将初学者工具包放入

/sites/all/themes/

而不是

/sites/default/themes/

我需要 Starterkit 来解决这个问题。是否有 {{ }} 来获取创建 Starterkit 的目录的路径?

【问题讨论】:

    标签: drupal drupal-theming


    【解决方案1】:

    您可以使用 drupal_add_jsdrupal_get_path 在您的 theme-settings.php 或 template.php 文件中将路径设为自定义设置:

    $theme_path = drupal_get_path('theme', 'my-theme');
    drupal_add_js(array('myCustomSetting' => array('path' => $theme_path)), 'setting');
    

    然后在您的 javascript 文件中,您可以引用如下设置:

    Drupal.settings.myCustomSetting + '/js/ckeditor_templates/'
    

    我建议让 drupal 为您构建路径,而不是尝试将其嵌入。

    关于动态构建子主题时哪些变量可用,我真的不知道。我所利用的只是您提到的 {{ THEME SANITIZED }} 值。

    我还没有测试过上面的东西,但是类似的东西应该可以正常工作。

    【讨论】:

      【解决方案2】:

      我可以确认 Drupal 没有为路径提供类似 {{ THEME SANITIZED }} 的东西。但是您可以通过 config.customConfig 变量从 CKEditor 配置中获取 ckeditor.config.js 文件的路径。因此,我们有足够的信息来创建主题路径。我只是剥离了文件名并将其用作路径。

      ekeditor.config.js

      CKEDITOR.editorConfig = function(config) {
        pathToTheme = config.customConfig.substring(0, config.customConfig.lastIndexOf("/"));
        config.templates_files = [ pathToTheme + '/js/ckeditor_templates/ckeditor_templates.js' ];
        yada yada yada,
      }
      

      ckeditor_templates.js

       CKEDITOR.addTemplates('default', {
         imagesPath: pathToTheme + '/js/ckeditor_templates/',
         templates: [yada yada yada],
       }
      });
      

      【讨论】:

        猜你喜欢
        • 2010-09-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-01-20
        • 1970-01-01
        • 1970-01-01
        • 2010-11-02
        • 2012-04-29
        相关资源
        最近更新 更多