Attach js to the module using libraries with inline property I have a module in which I have created a libraries.yml file and have attached it to the module:

$var[$delta] = array(
  '#theme' =&gt; 'example_theme',
  '#attached' =&gt; array(
    'library' =&gt; array(
      "example_theme/example-styling",
    ),
  ),
  '#file' =&gt; $output,
);


I want to provide a variable to the js defined in libraries.yml

How can I achieve this?

drupal_add_js('example = "' . $example . '";', 'inline')
drupal_add_js() has been deprecated, and you cannot use it anymore.

Pass the inline variables with the #attached property as :

$var[$delta]['#attached']['drupalSettings']['yourmodule']['example'] = $example;


And then access the example variable in the JS file as

drupalSettings.yourmodule.example


Note: I have not tried this code, but I think it should work.