I am writing some custom javascript in Joomla 4 Beta 6 to control various aspects of my custom front-end template's menus. It needs to load after the page has been rendered, so I want to add it at the bottom of the template's index.php file.
If I add the script in full it works fine. If I add the code to /js/user.js and then add the full URL link to the file - as if it was an external file - in the bottom of the index.php file, it also works, fine, e.g:
<script src="https://my.website.com/templates/my_template/js/user.js"></script>
However, I'd rather not have the full link visible, but if I try to add it via a local reference (using both double and single quotes), it doesn't work, e.g.:
<script src="/js/user.js"></script>
I have also tried adding a php instruction like this:
<?php $doc = JFactory::getDocument(); $doc->addScript('templates/'. $this->template . '/js/user.js'); ?>
Which works for the template.js at the top of the file, but it doesn't work in this position at the bottom, either.
What am I doing wrong? Thanks.