Skip to content

Commit

Permalink
Modulo en JavaScript
Browse files Browse the repository at this point in the history
1.- Modulo de javaScript que realiza HOLA MUNDO
2.- creamos el nuevo modulo
    app/code/Learning/Js/registration.php
    app/code/Learning/Js/etc/module.xml
3.- Creamos un archivo de modulo JavaScript:
    requirejs-config.js
    hello.js
4.- Creamos LAYOUT que habilita del modulo de JavaScript
    catalog_product_view.xml
5.- Creamos template que contiene el mensaje
    hello.phtml
6.- finalmente actualizamos nuestra BDD y si es necesario recopilamos
    php bin/magento setup:upgrade
    bin/magento setup:di:compile
    chmod -R 777 var/ pub/
    grep Learning_Js app/etc/config.php
  • Loading branch information
PerezContrerasLuis committed Jan 18, 2022
1 parent a4d78d0 commit 3569e15
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 0 deletions.
5 changes: 5 additions & 0 deletions code/Learning/Js/etc/module.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Learning_Js" setup_version="0.0.1">
</module>
</config>
13 changes: 13 additions & 0 deletions code/Learning/Js/registration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

use Magento\Framework\Component\ComponentRegistrar;

ComponentRegistrar::register(
ComponentRegistrar::MODULE,
'Learning_Js',
__DIR__
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0"?>
<page layout="1column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="content">
<block class="Magento\Framework\View\Element\Template" template="Learning_Js::hello.phtml" />
</referenceContainer>
</body>
</page>
7 changes: 7 additions & 0 deletions code/Learning/Js/view/frontend/requirejs-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
var config = {
map: {
'*': {
hello: 'Learning_Js/js/hello',
}
}
};
3 changes: 3 additions & 0 deletions code/Learning/Js/view/frontend/templates/hello.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div data-mage-init='{"hello": {"message": "HELLO WORLD!"}}'>
Content
</div>
9 changes: 9 additions & 0 deletions code/Learning/Js/view/frontend/web/js/hello.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
define([
"jquery"
], function($){
"use strict";
return function(config, element) {
alert(config.message);
}
}
)
1 change: 1 addition & 0 deletions etc/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@
'Learning_ClothingMaterial' => 1,
'Learning_FirstUnit' => 1,
'Learning_HelloPage' => 1,
'Learning_Js' => 1,
'Luisdev_Helloworld' => 1,
'PayPal_Braintree' => 1,
'PayPal_BraintreeGraphQl' => 1,
Expand Down

0 comments on commit 3569e15

Please sign in to comment.