0
votes

I have a custom Drupal Theme Starterkit. In it there is a JS file where I need to get the path to the current theme. Example:

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

Since it is possible that someone would put the starterkit in

/sites/all/themes/

instead of

/sites/default/themes/

I need the Starterkit to account for that. Is there a {{ }} to get the path to the directory where the Starterkit is being created?

2

2 Answers

1
votes

You could make the path a custom setting using drupal_add_js and drupal_get_path like this in your theme-settings.php or template.php file:

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

Then in your javascript file, you could reference the setting like:

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

I would suggest letting drupal to build the path for you, rather than trying to bake it in.

Regarding which variables are available when dynamically building a subtheme, I really don't know. All I've ever taken advantage of is the {{ THEME SANITIZED }} value you mention.

I haven't tested the above, but something like it should work just fine.

1
votes

I can confirm that Drupal does not provide a something like {{ THEME SANITIZED }} for a path. But you can get the path to the ckeditor.config.js file from the CKEditor config via config.customConfig variable. Therefore, we have enough information to create the path to the theme. I just stripped off the file name and used it as the path.

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],
 }
});