page.js.twig currently sets the page Javascript variable to import page-specific variables from the server into the client JS environment. However it looks like in some cases we load this partial both in the base page as well as dynamic components such as modal forms.
This means that the original value set in the base page gets completely overwritten when the modal form is loaded.
The simplest solution seems to be merging, rather than setting, the page variable by changing page.js.twig:
{# Page variables needed by client-side code (Javascript). #}
{% autoescape 'js' %}
if (typeof page === 'undefined') {
var page = {};
}
page = $.extend(
true, // deep extend
{{ page | json_encode(constant('JSON_PRETTY_PRINT')) | raw }},
page
);
{% endautoescape %}
This doesn't completely guarantee that nested values in page won't be overwritten, of course. But it at least provides a mechanism for easily setting additional client-side variables while keeping them scoped under the top-level page object.
page.js.twigcurrently sets thepageJavascript variable to import page-specific variables from the server into the client JS environment. However it looks like in some cases we load this partial both in the base page as well as dynamic components such as modal forms.This means that the original value set in the base page gets completely overwritten when the modal form is loaded.
The simplest solution seems to be merging, rather than setting, the page variable by changing
page.js.twig:This doesn't completely guarantee that nested values in
pagewon't be overwritten, of course. But it at least provides a mechanism for easily setting additional client-side variables while keeping them scoped under the top-levelpageobject.