Adding a custom JavaScript
Rate this topic: 




1.00 out of 6 based on 1 vote(s)






- GK User
- Tue Jul 22, 2014 10:54 am
- Reply with quote
- Report this post
Hi,
I would like to add a custom JS in the header, but this JS is related to a specific component developed for the site. So, the template related way to insert in the head block
can't work as it's not in the template folder (and I can't move it). The usual Joomla way
doesn't work either because it's generating a parse error. How can I call this script in the template ?
Thanks.
I would like to add a custom JS in the header, but this JS is related to a specific component developed for the site. So, the template related way to insert in the head block
- Code: Select all
$this->API->addJS($this->API->URLtemplate() . '/js/my_script.js');
can't work as it's not in the template folder (and I can't move it). The usual Joomla way
- Code: Select all
<script src="<?php echo $this->baseurl; ?>/components/com_mycomponent/assets/js/my_script.js" ></script>
doesn't work either because it's generating a parse error. How can I call this script in the template ?
Thanks.
-
- Fresh Boarder
- GK User
- Tue Jul 22, 2014 10:57 am
- Reply with quote
- Report this post
hi...I guess you use the wrong editor.
Please use "Editor - Code Mirror" and add the code again.
Please use "Editor - Code Mirror" and add the code again.
-
- Expert Boarder
- GK User
- Tue Jul 22, 2014 10:59 am
- Reply with quote
- Report this post
Or you can download a joomla module an add a js script like you want:
http://extensions.joomla.org/extensions ... ules/17122
http://extensions.joomla.org/extensions ... ules/17122
-
- Expert Boarder
- GK User
- Tue Jul 22, 2014 11:11 am
- Reply with quote
- Report this post
I can't see the link with a code editor or another… It's more likely a way to call for js in this template. Furthermore, I don't want a script in a module or a page (I'm already doing this with Sourcerer http://extensions.joomla.org/extensions/core-enhancements/coding-a-scripts-integration/custom-code-in-content/5051 for a nice exchange of best extensions
) but in the head of all pages.
So, continuing to looking for…
(PS : I did a typing mistake in my first post -> it's not "header" but "head")

So, continuing to looking for…
(PS : I did a typing mistake in my first post -> it's not "header" but "head")
-
- Fresh Boarder
- GK User
- Sat Jul 26, 2014 1:16 pm
- Reply with quote
- Report this post
For those interested, solution is : to include script in your head area, just open file layouts/default.php where the HEAD opening and closing tag is visible and include script in regular way without using Joomla API so provide full path to site :
- Code: Select all
<script src="http://urlofyourwebsite.com/components/com_mycomponent/assets/js/my_script.js" ></script>
-
- Fresh Boarder
5 posts
• Page 1 of 1