I add a variable in the backend to a render array like so (removed superfluous code):
$some_var = 'Hello World';
return [
'#attached' => [
'drupalSettings' => ['someVar' => $some_var],
],
'#theme' => 'core_portal_customer_subscription_edit',
'#data' => [
'namespace_something' => $some_var,
]
];
I would then like to use that variable in my JavaScript but I can't seem to access the drupalSettings.
I tried doing the following but that console.logs undefined.
(function($, Druapl, drupalSettings) {
Drupal.behaviors.escrowPortalCore = {
...
console.log(druaplSettings.someVar);
}
}());