Advertisement
Adding custom js and css in a child template J5
Moderators: ooffick, General Support Moderators
Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10.
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10.
-
- Joomla! Apprentice
- Posts: 14
- Joined: Fri Apr 12, 2024 2:16 pm
Adding custom js and css in a child template J5
Can I hijack this question?
I am working on a new Joomla 5 Page and use a cassiopeia child template.
there i have a css and a js folder with my user.css respectively user.js files
CSS is working fine
But the user.js is not recognized
When I put my individual JS Code in the template.js of the parent template it works fine. Problem is, it's not update-proof.
What am I missing?
Is there any place I have to enter the user.js of my child-template for it to work?
I am working on a new Joomla 5 Page and use a cassiopeia child template.
there i have a css and a js folder with my user.css respectively user.js files
CSS is working fine
But the user.js is not recognized
When I put my individual JS Code in the template.js of the parent template it works fine. Problem is, it's not update-proof.
What am I missing?
Is there any place I have to enter the user.js of my child-template for it to work?
Last edited by AMurray on Tue Sep 03, 2024 9:52 am, edited 1 time in total.
Reason: split from https://forum.joomla.org/viewtopic.php?f=833&t=1008133. Hijacking other posts is against forum rules. Please create your own question in future even if the topic is similar in nature.
Reason: split from https://forum.joomla.org/viewtopic.php?f=833&t=1008133. Hijacking other posts is against forum rules. Please create your own question in future even if the topic is similar in nature.
Advertisement
-
- Joomla! Explorer
- Posts: 347
- Joined: Fri Aug 19, 2005 12:12 pm
- Location: Out of my mind ...sometimes
Re: Adding custom js and css in a child template J5
user.css should be in:
/media/templates/site/cassiopeia_my_child_template/css/user.css
user.js should be in:
/media/templates/site/cassiopeia_my_child_template/js/user.js
/media/templates/site/cassiopeia_my_child_template/css/user.css
user.js should be in:
/media/templates/site/cassiopeia_my_child_template/js/user.js
-
- Joomla! Apprentice
- Posts: 14
- Joined: Fri Apr 12, 2024 2:16 pm
Re: Adding custom js and css in a child template J5
That's exactly what I did. But the "user.js" (resp. the "user.min.js" have no effect on the page.
You do not have the required permissions to view the files attached to this post.
-
- Joomla! Apprentice
- Posts: 14
- Joined: Fri Apr 12, 2024 2:16 pm
Re: Adding custom js and css in a child template J5
@AMurray: sorry for hijacking the other post, it will not happen again. And thanks for creating a separate one
-
- Joomla! Explorer
- Posts: 347
- Joined: Fri Aug 19, 2005 12:12 pm
- Location: Out of my mind ...sometimes
Re: Adding custom js and css in a child template J5
In this file:
/templates/cassiopeia/joomla.asset.json
NB: it belongs to cassiopeia, but is applied to its child too.
Check this:
and change user.js to user.min.js in
I am not sure you can duplicate this to implement both files though.
And I guess you'll have to rename the file in cassiopeia parent folder as well.
/templates/cassiopeia/joomla.asset.json
NB: it belongs to cassiopeia, but is applied to its child too.
Check this:
Code: Select all
{
"name": "template.user",
"description": "The name of a file where a user can add their own javascript",
"type": "script",
"uri": "user.js",
"dependencies": [
"template.active"
]
},
Code: Select all
"uri": "user.js",
And I guess you'll have to rename the file in cassiopeia parent folder as well.
-
- Joomla! Apprentice
- Posts: 14
- Joined: Fri Apr 12, 2024 2:16 pm
Re: Adding custom js and css in a child template J5
Thanks for the help!
I tried it as described, but still, my JS is only working, when put in the template.js.
BUT, i found a solution that worked for me in another forum:
I put my JS Code in the user.js in this bracket:
now it works
I tried it as described, but still, my JS is only working, when put in the template.js.
BUT, i found a solution that worked for me in another forum:
I put my JS Code in the user.js in this bracket:
Code: Select all
document.addEventListener("DOMContentLoaded", function(){
/* MY CODE */
});
-
- Joomla! Explorer
- Posts: 347
- Joined: Fri Aug 19, 2005 12:12 pm
- Location: Out of my mind ...sometimes
Re: Adding custom js and css in a child template J5
Well, this has nothing to do with joomla and the location/naming of js files.
This has to do with the placement of js files in between <head> </head>, which is the default placement of js files in joomla, and the necessary correction in the js script.
This has to do with the placement of js files in between <head> </head>, which is the default placement of js files in joomla, and the necessary correction in the js script.
- Webdongle
- Joomla! Master
- Posts: 44448
- Joined: Sat Apr 05, 2008 9:58 pm
Re: Adding custom js and css in a child template J5
Please provide a screenshot of the file structure not a section of one
http://www.weblinksonline.co.uk/
https://www.weblinksonline.co.uk/updating-joomla.html
"When I'm right no one remembers but when I'm wrong no one forgets".
https://www.weblinksonline.co.uk/updating-joomla.html
"When I'm right no one remembers but when I'm wrong no one forgets".
Advertisement