In my Drupal 7 theme I store a CSS file in the public files directory so that the submit handler of the theme settings form can write to the file to effectuate certain theme settings:

  // Load Theme Theme Settings CSS File
  $files_path = variable_get('file_public_path', conf_path() . '/files');
  if (is_file($files_path . '/example-themesettings-' . $theme . '.css')) {
      $files_path . '/example-themesettings-' . $theme . '.css', array(
        'preprocess' => variable_get('preprocess_css', '') == 1 ? TRUE : FALSE,
        'group' => CSS_THEME,
        'media' => 'all',
        'every_page' => TRUE,
        'weight' => 100

Is this possible in Drupal 8 in a theme's example.libraries.yml file? I can't find any documentation about using tokens for paths in YAML files but if that possibility does exist that would be great.

If not I'll have to do it like color module does it and use hook_library_info_alter to add dynamic paths.

  • Why do you need to write to a file? From the sound of it, it looks like you're saving some sort of config. Can't you use the config system instead? – Joseph May 25 '17 at 13:24
  • I haven't tried this, but this page (drupal.org/node/2201089) says "However, absolute paths (e.g., /core/assets/vendor/...) as well as (stream wrapper) URIs (e.g., example.com/foo.js or public://color/bartik/color.css) as well as protocol-free URIs (e.g., //api.google.com/jquery.js) are supported, too. " – rjl May 25 '17 at 19:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.