django-cms this.ui.container.data(...).push is not a function
June 19, 2021, 7:02 a.m.
In django 3.7.X (possibly in an earlier version) until current 3.8.0 (at the time of writing) has an error when opening the page structure:
`Uncaught TypeError: this.ui.container.data(...).push is not a function at s.initialize (bundle.toolbar.min.js:1)
It occurs when the template has several static_placeholder
with the same names, for example: {% static_placeholder 'header' %}
.
There is an issue https://github.com/django-cms/django-cms/issues/6889 on Github, and developers have not fixed this case at this moment.
By digging around in the bundle.toolbar.min.js
file where the error occurs, I was able to find a workaround.
Workaround
Copy /path_to_env_of_my_project/lib/python3.8/site-packages/cms/static/cms/js/dist/3.8.0/bundle.toolbar.min.js
file to /path_to_my_project/static/cms/js/dist/3.8.0/bundle.toolbar.min.js
.
Note that instead of the 3.8.0
folder name, use the folder name corresponding to the version of django-cms you are using. If you are using django-cms == 3.7.4
, then the path will be like path_to_my_project/static/cms/js/dist/3.7.4/bundle.toolbar.min.js
This file contains minified (compressed) js code, so you can reformat the code in this file for convenience. In PyCharm, this is done in menu Code \ Reformat code
(hotkey Ctrl + Alt + L).
Then, before the code where the error occurs (you can find the line, for example, through the Google developer tools and search for the line of code in the file), add if (Array.isArray(this.ui.container.data("cms")))
:
...case"plugin":if (Array.isArray(this.ui.container.data("cms"))) this.ui.container.data("cms").push(this.options), xe.aliasPluginDuplicatesMap[this.options.plugin_id] = !0, this._setPlugin(), _e() && this._collapsables();...
Now django-cms will pick up the new file and there should be no more errors.
Also keep in mind that I tested this method only on django-cms version 3.8.0, so it's not a fact that it might work with other versions.
You can also download my corrected bundle.toolbar.min.js
for django-cms == 3.8.0
:
bundle.toolbar.min.js (668.2 KB)
Comments: 0