Advertisement

Adding custom js and css in a child template J5

For Joomla! 5.x Coding related discussions, you could also use: http://groups.google.com/group/joomla-dev-general

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.
Post Reply
Roland_S
Joomla! Apprentice
Joomla! Apprentice
Posts: 14
Joined: Fri Apr 12, 2024 2:16 pm

Adding custom js and css in a child template J5

Post by Roland_S » Tue Sep 03, 2024 8:55 am

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?
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.

Advertisement
ghazal
Joomla! Explorer
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

Post by ghazal » Tue Sep 03, 2024 11:16 am

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

Roland_S
Joomla! Apprentice
Joomla! Apprentice
Posts: 14
Joined: Fri Apr 12, 2024 2:16 pm

Re: Adding custom js and css in a child template J5

Post by Roland_S » Tue Sep 03, 2024 11:40 am

joomla5_child-template_structure.png
Thanks for the reply.
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.

Roland_S
Joomla! Apprentice
Joomla! Apprentice
Posts: 14
Joined: Fri Apr 12, 2024 2:16 pm

Re: Adding custom js and css in a child template J5

Post by Roland_S » Tue Sep 03, 2024 11:41 am

@AMurray: sorry for hijacking the other post, it will not happen again. And thanks for creating a separate one

ghazal
Joomla! Explorer
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

Post by ghazal » Tue Sep 03, 2024 12:33 pm

In this file:
/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"
      ]
    },
and change user.js to user.min.js in

Code: Select all

"uri":  "user.js",
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.

Roland_S
Joomla! Apprentice
Joomla! Apprentice
Posts: 14
Joined: Fri Apr 12, 2024 2:16 pm

Re: Adding custom js and css in a child template J5

Post by Roland_S » Tue Sep 03, 2024 1:07 pm

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:

Code: Select all

document.addEventListener("DOMContentLoaded", function(){
/* MY CODE */
});
now it works

ghazal
Joomla! Explorer
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

Post by ghazal » Tue Sep 03, 2024 3:04 pm

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.

User avatar
Webdongle
Joomla! Master
Joomla! Master
Posts: 44448
Joined: Sat Apr 05, 2008 9:58 pm

Re: Adding custom js and css in a child template J5

Post by Webdongle » Thu Sep 05, 2024 3:40 am

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".

Advertisement

Post Reply

Return to “Joomla! 5.x Coding”