How to Add custom Jquery to my template

More
8 years 3 months ago #35472 by dries
Hello.

I am trying to add custom jquery to my template.

If someone could please help me with this, I would be extremely grateful.

Where should I place my script tags?
EG -
<script src=" ajax.googleapis.com/ajax/libs/jquery/2.2.3/jquery.min.js ">
<script src="assets/js/jquery-2.2.3.min.js "></script>
<script src="assets/js/bootstrap.min.js"></script>
<script src="assets/js/main.js"></script>

I adding custom code within template creator ck that references my file that i created in my locahost file structure

If I create a folder in the template with the files, it just keeps getting overwritten when I copy new changes into the template.

Thank you in regards.

Please Log in or Create an account to join the conversation.

More
8 years 3 months ago #35478 by ced1870
Hi

<script src="ajax.googleapis.com/ajax/libs/jquery/2.2.3/jquery.min.js"></script>
<script src="assets/js/jquery-2.2.3.min.js "></script>
<script src="assets/js/bootstrap.min.js"></script>

you shall never do that. jQuery is included into Joomla! so you must call it using the API
Code:
JHtml::_('jquery.framework');

you can keep this
Code:
<script src="assets/js/main.js"></script>
to add in the Parameters >> custom code

your files shall be kept in place if you put them directly into the template folder

CEd

Joomlack Webmaster and Developer

Please Log in or Create an account to join the conversation.

More
8 years 3 months ago #35479 by dries
Hello.

Thank you very much for your response.

Please see my attached screenshots.

I am not sure where to place the javascript file.
1 ) is it in root/templates/mytemplate/js/main.js
or
2 ) is it in root/components/com_templateck/projects/mytemplate/js.

If I put it in nr 2 and I make changes and copy it into the template it keeps being deleted.

Im also not sure where to call the api:
JHtml::_('jquery.framework');

I apprecite your help more than you can imagine.

Thank you so much.
Attachments:

Please Log in or Create an account to join the conversation.

More
8 years 3 months ago #35505 by ced1870
you should be able to put your js file directly in the template (solution No 1)
for your code, this is correct (what I see on the picture), to call jQuery and then your script. only the path to your script is not correct

you can check my cheatsheet to help you ;)
www.joomlack.fr/en/joomla-documentations...templates-cheatsheet

Joomlack Webmaster and Developer
The following user(s) said Thank You: dries

Please Log in or Create an account to join the conversation.

More
8 years 3 months ago #35506 by dries
Thank you very much.

I will go and try to figure this out more.

Dries

Please Log in or Create an account to join the conversation.

More
8 years 3 months ago #35511 by dries
Ok, so I figured it out and now works.

I have attached screenshots.

Hopefully this helps someone else out who is struggling...

My issue was with using '$' instead of 'jQuery' as well as referencing of the script file.

Thank you for your help.

Regards
Attachments:
The following user(s) said Thank You: ced1870

Please Log in or Create an account to join the conversation.

Time to create page: 0.550 seconds

Fast and powerful creation, customizable and responsive.

Read More

We have 1273 guests and no members online