when using addScriptDeclaration
, the script is added in the first tag that is found inside the HEAD tag.
Is it possible to add it just before </HEAD>
?
Joomla Stack Exchange is a question and answer site for Joomla! administrators, users, developers and designers. It only takes a minute to sign up.
Sign up to join this communitywhen using addScriptDeclaration
, the script is added in the first tag that is found inside the HEAD tag.
Is it possible to add it just before </HEAD>
?
You can do this by using the new feature Child Templates in Joomla 4.1. Step by step details:
index.php
under /templates/cassiopeiaindex.php
templateDetails.xml
and add the following code:<field name="myJS" type="textarea" label="My JS script" />
index.php
file, and add this new line inside <head>
</head>
tags:<script><?php echo $this->params->get('myJS'); ?></script>
That's all !
All credit goes to Dimitris Grammatiko and his presentation on JUG London !
Yes you can put in the head, but its most common to put it before the tag
<head></head>
as the last child inside of it. In other words, the OP is trying to ensure that the declaration comes after all other declarations in the head tag. Please do not extend your answer's advice by adding comments. When you have additional relevant details to add, please edit your post so that the whole story is in one cohesive place (then delete your comment).
There is a "dirty" way to do this. Use regular labs rereplacer and simply replace in the head and replace
with something before ithttps://www.regularlabs.com/extensions/rereplacer
The swiss army penknife of the joomla world