I try to learn how to create a simple module in Magento 2. I create one but I have a lot of errors. If anyone can help me with a sample. How I can create a simple Magento2 module. This module must have the following:
1. to have layout folder (I want to call a custom javascript file that require jquery);
2. template folder (I want to add a phtml file);
3. to have enable / disable option in the admin panel;
1 Answer 1
Some Helpful Links
1) Magento 2 Module Creator
https://github.com/darshanb87/magento2-module-creator
2) Hello World Simple module in Magento 2
https://www.mageplaza.com/kb/how-create-hello-world-module-magento-2.html
OR
http://inchoo.net/magento-2/how-to-create-a-basic-module-in-magento-2/
For Adding jQuery
put your jQuery files inside web/js folder and add requirejs-config.js file
var config = {
'map': {
'*': {
loader: 'Vendor_Module/js/jquery.loader',
menu: 'Vendor_Module/js/jquery.menu'
}
}
};
For Enable/Disable - create system.xml file in below location
app/code/Vendor/Module/etc/adminhtml/system.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
<system>
<section id="test" translate="label" sortOrder="130" showInDefault="1" showInWebsite="1" showInStore="1">
<class>separator-top</class>
<label>Module</label>
<tab>general</tab>
<resource>Vendor_Module::config_notes</resource>
<group id="view" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Module View Settings</label>
<field id="enabled" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Enable Module On Frontend</label>
<source_model>Magento\Backend\Model\Config\Source\Yesno</source_model>
</field>
</group>
</section>
</system>
</config>
-
the problem here is that I add in my module layout folder default.xml file, and I call the js and css files there but my js file is in front of jquery and this is jquery dependent, for that I ask for a working module with my requirementsRobert– Robert2017年11月27日 21:54:08 +00:00Commented Nov 27, 2017 at 21:54
-
check my updated answer to add and load jQuery filesAbhishek Panchal– Abhishek Panchal2017年11月27日 21:58:59 +00:00Commented Nov 27, 2017 at 21:58
-
Thanks and how I can call the phtml file? and how I can add that enable / disable admin function?Robert– Robert2017年11月27日 21:59:43 +00:00Commented Nov 27, 2017 at 21:59
-
I already do this what you told me with the requirejs-config but my files in luma theme for example are in the front of allRobert– Robert2017年11月27日 22:01:39 +00:00Commented Nov 27, 2017 at 22:01
-
please update your question with what you want and problem you are facingAbhishek Panchal– Abhishek Panchal2017年11月27日 22:02:45 +00:00Commented Nov 27, 2017 at 22:02
Explore related questions
See similar questions with these tags.