Zotonic 1.x import js with es6 without lib?

Hello guys i need import just some functions of my js file, without import all the file with lib ? it’s possible something like this:

{% javascript %}
   import { useCall } from 'lib/js/test.js';
   useCall(test);
{% endjavascript %}
5 Likes

Currently not, the javascript tag does not interpret javascript. It allows you to put verbatim javascript on your page, but with the extra addition that you can add template variables and use all template language additions. After rendering, the text is placed on the page.

Example:

{% javascript %}
   console.log("Current page", {{ id }});
   console.log("Current user", {{ m.acl.user }});
{% endjavascript %}

In order to support something like this we have to be able to run the javascript itself I think.

4 Likes

thanks.

2 Likes

It would probably possible to add something like this by integrating something like deno (https://deno.land) into a custom zotonic tag (Create a custom tag @ Zotonic). That way you could can let deno compile the desired javascript, which is then embedded on the page. It would then even support typescript.

3 Likes