Add external CSS file with custom backend setting I'm trying to add a external CSS file. The client wants to be able to change the url from the backend. Creating a backend settings form is not an issue, but I can't seem to get the file loaded in the frontend.

My code:

function MYTHEME_library_info_build() {
  $libraries = [];
  $libraries['mylibrary'] = [
    'version' =&gt; '1.0',
    'css' =&gt; [
      'base' =&gt; [
        'https://www.mywebsite.com/css/styles.css' =&gt; [],
      ],
    ],
  ];

  return $libraries;
}


The fixed url will be replaced with a variable containing the value entered in the backend.
hook_library_info_build() would be the right hook to add dynamic library definitions (definitions that depend on any run-time information) but it needs to be implemented by a module, as its documentation page says.


  Modules may implement this hook to add dynamic library definitions. Static libraries, which do not depend on any runtime information, should be declared in a modulename.libraries.yml file instead.


hook_library_info_alter() can be implemented by either a module or a theme.


  Allows modules and themes to change libraries' definitions; mostly used to update a library to a newer version, while ensuring backward compatibility. In general, such manipulations should only be done to extend the library's functionality in a backward-compatible way, to avoid breaking other modules and themes that may be using the library.


If there are default values you can use (for example, using a local CSS file that is then replaced from hook_library_info_alter() basing on run-time information), you can put those default values in the .libraries.yml file, and use hook_library_info_alter() to alter them.