1

I was needing to add a Jquery library in magento 1.9, to use on one of my phtml pages, to insert masks in my fields, like cpf, cnpj and etc ...

I have done a lot of research and I have noticed that the subject is very scarce, but very necessary, and I want to share this knowledge with you. There are a lot of details to watch out for, but with a lot of patience it works, I discovered the right and proper method to do this, and I also discovered the fast method if the first method does not work.

  • Is Magento 1 still alive? :) and jquery problem still exist? :D There is an IT world where time flows much slower :D – Bartosz Herba Nov 14 '17 at 20:23
  • I am putting this example to anyone who uses version 1.9 and is encountering this problem. – Philip Ramkeerat Nov 14 '17 at 20:28
1

Well, I researched a lot and got two solutions, the first time, you added to the Jquery.js file that thinks of the magento/js/jquery/your-lib.js directory.

Done this, you will look at the page.xml file and add an addJs method that points to the location where you are inserting yourjquery.js file. (AddJS function, I will explain below)

Location ex: app/design/frontend/default/yourtheme/layout/page.xml.

Okay, coming out with no page.xml you'll see a method calling addJS which is basically a native function of Magento that aims to search the Magento JS directory, the file you want to add. Pay close attention here, you are already prepared to search the JS folder of the Magento, so basically, you do not like pasta.

So let's for example, add a JQuery.js library:

<action method = "addJs"> <script> jquery / name-of-your-lib-jquery.js </ script> </ action>

Note that I did not type js/jquery/... I just typed jquery/... being so following what I said above, which is already set and is not accurate Be referenced in your directory information.

Follow your steps and you do not have your Magento and your Jquery library, and then just use it for free. To find out what is working, reload the Magento, activate the browser console and search, not HTML a head tag and see the jquery libraries there, if it is showing up there, it is ok.

IF YOU DID NOT GET USING THE FIRST (MOST RECOMMENDED) METHOD ... Remember it may be easier, but I advise you to use the first way ...

SECOND WAY

It's basically the first thing you think about when it comes to doing something like that.

<script type="text/javascript" src="<?php echo $this->getJsUrl('jquery/name-of-your-lib-jquery.js')?>"></script>

Final remarks: Syntax Jquery Magento 1.9

It's not your .phtml file, when you use a function without your Jquery, it uses your library you just added, and you get the error. Try using this syntax style:

jQuery ('input [id = "billing: example"]'). mask ("(00) 00000-0000");
  • After 10 years? Are you serious? :DD Magento ver 1.0.0 - Added March 31, 2008 I have a strong feeling that someone has already described it here, at least once :D – Bartosz Herba Nov 14 '17 at 20:48
  • Thank you my friend, I just want to help someone, with a headache I had – Philip Ramkeerat Nov 28 '17 at 2:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.