We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

javascript module

Is there a way to manage javascript modules using Phalcon\Assets ?

edited 21h ago

I've done it adding in the asset plugin

->addJs("$currentPath/".((ENV==="prod") ? 'build' : 'main').'.mjs');

and in the layout

<? foreach($this->assets->collection('mjs')->getAssets() as $asset): ?>
    <script type="module" src="/<?=$this->assets->collection('mjs')->getPrefix().$asset->getPath()?>?v=<?=$this->config->version?>"></script>
<? endforeach; ?>

but I would like to create a function like outputJs (outputMjs) to do the job in the layout. How can I do this ?