GlennRicaud / data-toolbox-app

Apache License 2.0
11 stars 1 forks source link

Change how config is passed to the widget #86

Closed alansemenov closed 4 days ago

alansemenov commented 5 days ago

Currently config is passed via "config" attribute of the widget script:

<script src="/_/asset/systems.rcd.enonic.datatoolbox:1731062259909/js/export.js" type="text/javascript" config="{&quot;servicesUrl&quot;:&quot;/admin/com.enonic.app.contentstudio/main/_/service/systems.rcd.enonic.datatoolbox&quot;,&quot;assetsUrl&quot;:&quot;/_/asset/systems.rcd.enonic.datatoolbox:1731062259909&quot;,&quot;cmsRepositoryShortName&quot;:&quot;sample-blog&quot;,&quot;branchName&quot;:&quot;draft&quot;,&quot;contentPath&quot;:&quot;/superhero&quot;,&quot;contentName&quot;:&quot;superhero&quot;}"></script>

In Content Studio 6 contents of widget template will be sanitised and all unknown attributes except those prefixed with "data-" will be stripped.

So, please either rename "config" to "data-config" or, better, change how you pass config to the widget so that config json is inlined inside a script tag. See example below.

In the widget template:

<script src="/_/asset/com.enonic.app.myapp/js/myapp.js" type="text/javascript">
<script id="myapp-config-json" type="application/json">{
    "appName": "com.enonic.app.myapp",
    "autoOpen": true,
    "phrases": {
        "linkLogout": "Log out",
        "tooltipOpenMenu": "Open XP menu",
        "tooltipCloseMenu": "Close XP menu"
    },
    "theme": "dark"
}</script>

In the widget JS:

const appConfigEl = document.getElementById('myapp-config-json');
const config = JSON.parse(appConfigEl.innerText);
GlennRicaud commented 4 days ago

Hehe it was actually like this before DT 5.0.24 but then I had to make this change for Content Studio 4.1

See changelog:

5.0.24 Apr 4th 2022

    Adaptation: Export widget: Removed inline JS (Required by Content Studio 4.1) - Compatibility:7.3.0
    Compatibility:
        7.3.0

But I can revert and have inline JS back, which I prefered also but are you sure about it?

GlennRicaud commented 4 days ago

Because here is your original comment:

Screenshot 2024-11-09 at 12 00 47
GlennRicaud commented 4 days ago

Fixed in DT 5.1.5