How to pass variable from phtml and how to get variable in require js file Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?Magento 2: can't use materialize.js on my custom modulehow to pass a custom variable from phtml file to email templateMagento 2.0 Pass custom input in phtml to controllerHow To Implement JavaScript Snippet in Magento .PHTML file so that it works?Accessing variables from another require JS moduleGet function/value from php file in .phtmlPass variable from phtml to jsjs file not loading in ajax returned phtml file magento2how to pass a variable from one phtml to another?Pass the value from the block class to the phtml file and not working in custom module

Caught masturbating at work

Why is the change of basis formula counter-intuitive? [See details]

What does it mean that physics no longer uses mechanical models to describe phenomena?

Why are vacuum tubes still used in amateur radios?

How does TikZ render an arc?

Tannaka duality for semisimple groups

Why shouldn't this prove the Prime Number Theorem?

Asymptotics question

Tips to organize LaTeX presentations for a semester

Nose gear failure in single prop aircraft: belly landing or nose-gear up landing?

Random body shuffle every night—can we still function?

Why not use the yoke to control yaw, as well as pitch and roll?

In musical terms, what properties are varied by the human voice to produce different words / syllables?

Does silver oxide react with hydrogen sulfide?

A term for a woman complaining about things/begging in a cute/childish way

What does Turing mean by this statement?

Delete free apps from Play Store library

The Nth Gryphon Number

Putting class ranking in CV, but against dept guidelines

Should a wizard buy fine inks every time he want to copy spells into his spellbook?

Does the Mueller report show a conspiracy between Russia and the Trump Campaign?

Co-worker has annoying ringtone

Can an iPhone 7 be made to function as a NFC Tag?

Most effective melee weapons for arboreal combat? (pre-gunpowder technology)



How to pass variable from phtml and how to get variable in require js file



Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)
Announcing the arrival of Valued Associate #679: Cesar Manara
Unicorn Meta Zoo #1: Why another podcast?Magento 2: can't use materialize.js on my custom modulehow to pass a custom variable from phtml file to email templateMagento 2.0 Pass custom input in phtml to controllerHow To Implement JavaScript Snippet in Magento .PHTML file so that it works?Accessing variables from another require JS moduleGet function/value from php file in .phtmlPass variable from phtml to jsjs file not loading in ajax returned phtml file magento2how to pass a variable from one phtml to another?Pass the value from the block class to the phtml file and not working in custom module



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








2















How to pass parameter form .phtml to require js file



Template file



<script type="text/javascript">
require(['Namespace_Module/js/custom'], function ()
);
</script>


JS file



define(['jquery'], function ($) 

//here need to get parameter

);









share|improve this question
























  • if my answer is helpful to you then you can accept as answer. so it will be useful to another user. Thanks :)

    – Chirag Patel
    Mar 18 at 11:02

















2















How to pass parameter form .phtml to require js file



Template file



<script type="text/javascript">
require(['Namespace_Module/js/custom'], function ()
);
</script>


JS file



define(['jquery'], function ($) 

//here need to get parameter

);









share|improve this question
























  • if my answer is helpful to you then you can accept as answer. so it will be useful to another user. Thanks :)

    – Chirag Patel
    Mar 18 at 11:02













2












2








2


1






How to pass parameter form .phtml to require js file



Template file



<script type="text/javascript">
require(['Namespace_Module/js/custom'], function ()
);
</script>


JS file



define(['jquery'], function ($) 

//here need to get parameter

);









share|improve this question
















How to pass parameter form .phtml to require js file



Template file



<script type="text/javascript">
require(['Namespace_Module/js/custom'], function ()
);
</script>


JS file



define(['jquery'], function ($) 

//here need to get parameter

);






magento2 javascript phtml requirejs






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 19 at 16:45









Rafael Corrêa Gomes

4,73523366




4,73523366










asked Mar 18 at 10:31









Vamsy KrishnaVamsy Krishna

162




162












  • if my answer is helpful to you then you can accept as answer. so it will be useful to another user. Thanks :)

    – Chirag Patel
    Mar 18 at 11:02

















  • if my answer is helpful to you then you can accept as answer. so it will be useful to another user. Thanks :)

    – Chirag Patel
    Mar 18 at 11:02
















if my answer is helpful to you then you can accept as answer. so it will be useful to another user. Thanks :)

– Chirag Patel
Mar 18 at 11:02





if my answer is helpful to you then you can accept as answer. so it will be useful to another user. Thanks :)

– Chirag Patel
Mar 18 at 11:02










1 Answer
1






active

oldest

votes


















2














In your phtml file you can add a parameter as the code below.



<script type="text/x-magento-init">

"*":
"Namespace_Modulename/js/myJs":
"customVar": "<?= 'Your parameter'; ?>"



</script>


In you js file add below code.



define([
'jquery',
'mage/url'
], function ($, url)
'use strict';

return function (config)

var customVar = config.customVar;
console.log(customVar);

);


In above code customVar is equal to you need to pass your parameter, you can pass multiple parameters to create a new variable.



I hope it helps!






share|improve this answer

























    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "479"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f266323%2fhow-to-pass-variable-from-phtml-and-how-to-get-variable-in-require-js-file%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    In your phtml file you can add a parameter as the code below.



    <script type="text/x-magento-init">

    "*":
    "Namespace_Modulename/js/myJs":
    "customVar": "<?= 'Your parameter'; ?>"



    </script>


    In you js file add below code.



    define([
    'jquery',
    'mage/url'
    ], function ($, url)
    'use strict';

    return function (config)

    var customVar = config.customVar;
    console.log(customVar);

    );


    In above code customVar is equal to you need to pass your parameter, you can pass multiple parameters to create a new variable.



    I hope it helps!






    share|improve this answer





























      2














      In your phtml file you can add a parameter as the code below.



      <script type="text/x-magento-init">

      "*":
      "Namespace_Modulename/js/myJs":
      "customVar": "<?= 'Your parameter'; ?>"



      </script>


      In you js file add below code.



      define([
      'jquery',
      'mage/url'
      ], function ($, url)
      'use strict';

      return function (config)

      var customVar = config.customVar;
      console.log(customVar);

      );


      In above code customVar is equal to you need to pass your parameter, you can pass multiple parameters to create a new variable.



      I hope it helps!






      share|improve this answer



























        2












        2








        2







        In your phtml file you can add a parameter as the code below.



        <script type="text/x-magento-init">

        "*":
        "Namespace_Modulename/js/myJs":
        "customVar": "<?= 'Your parameter'; ?>"



        </script>


        In you js file add below code.



        define([
        'jquery',
        'mage/url'
        ], function ($, url)
        'use strict';

        return function (config)

        var customVar = config.customVar;
        console.log(customVar);

        );


        In above code customVar is equal to you need to pass your parameter, you can pass multiple parameters to create a new variable.



        I hope it helps!






        share|improve this answer















        In your phtml file you can add a parameter as the code below.



        <script type="text/x-magento-init">

        "*":
        "Namespace_Modulename/js/myJs":
        "customVar": "<?= 'Your parameter'; ?>"



        </script>


        In you js file add below code.



        define([
        'jquery',
        'mage/url'
        ], function ($, url)
        'use strict';

        return function (config)

        var customVar = config.customVar;
        console.log(customVar);

        );


        In above code customVar is equal to you need to pass your parameter, you can pass multiple parameters to create a new variable.



        I hope it helps!







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Mar 19 at 16:03









        Rafael Corrêa Gomes

        4,73523366




        4,73523366










        answered Mar 18 at 10:43









        Chirag PatelChirag Patel

        2,648423




        2,648423



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Magento Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f266323%2fhow-to-pass-variable-from-phtml-and-how-to-get-variable-in-require-js-file%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Masuk log Menu navigasi

            Identifying “long and narrow” polygons in with PostGISlength and width of polygonWhy postgis st_overlaps reports Qgis' “avoid intersections” generated polygon as overlapping with others?Adjusting polygons to boundary and filling holesDrawing polygons with fixed area?How to remove spikes in Polygons with PostGISDeleting sliver polygons after difference operation in QGIS?Snapping boundaries in PostGISSplit polygon into parts adding attributes based on underlying polygon in QGISSplitting overlap between polygons and assign to nearest polygon using PostGIS?Expanding polygons and clipping at midpoint?Removing Intersection of Buffers in Same Layers

            Старые Смолеговицы Содержание История | География | Демография | Достопримечательности | Примечания | НавигацияHGЯOLHGЯOL41 206 832 01641 606 406 141Административно-территориальное деление Ленинградской области«Переписная оброчная книга Водской пятины 1500 года», С. 793«Карта Ингерманландии: Ивангорода, Яма, Копорья, Нотеборга», по материалам 1676 г.«Генеральная карта провинции Ингерманландии» Э. Белинга и А. Андерсина, 1704 г., составлена по материалам 1678 г.«Географический чертёж над Ижорскою землей со своими городами» Адриана Шонбека 1705 г.Новая и достоверная всей Ингерманландии ланткарта. Грав. А. Ростовцев. СПб., 1727 г.Топографическая карта Санкт-Петербургской губернии. 5-и верстка. Шуберт. 1834 г.Описание Санкт-Петербургской губернии по уездам и станамСпецкарта западной части России Ф. Ф. Шуберта. 1844 г.Алфавитный список селений по уездам и станам С.-Петербургской губернииСписки населённых мест Российской Империи, составленные и издаваемые центральным статистическим комитетом министерства внутренних дел. XXXVII. Санкт-Петербургская губерния. По состоянию на 1862 год. СПб. 1864. С. 203Материалы по статистике народного хозяйства в С.-Петербургской губернии. Вып. IX. Частновладельческое хозяйство в Ямбургском уезде. СПб, 1888, С. 146, С. 2, 7, 54Положение о гербе муниципального образования Курское сельское поселениеСправочник истории административно-территориального деления Ленинградской области.Топографическая карта Ленинградской области, квадрат О-35-23-В (Хотыницы), 1930 г.АрхивированоАдминистративно-территориальное деление Ленинградской области. — Л., 1933, С. 27, 198АрхивированоАдминистративно-экономический справочник по Ленинградской области. — Л., 1936, с. 219АрхивированоАдминистративно-территориальное деление Ленинградской области. — Л., 1966, с. 175АрхивированоАдминистративно-территориальное деление Ленинградской области. — Лениздат, 1973, С. 180АрхивированоАдминистративно-территориальное деление Ленинградской области. — Лениздат, 1990, ISBN 5-289-00612-5, С. 38АрхивированоАдминистративно-территориальное деление Ленинградской области. — СПб., 2007, с. 60АрхивированоКоряков Юрий База данных «Этно-языковой состав населённых пунктов России». Ленинградская область.Административно-территориальное деление Ленинградской области. — СПб, 1997, ISBN 5-86153-055-6, С. 41АрхивированоКультовый комплекс Старые Смолеговицы // Электронная энциклопедия ЭрмитажаПроблемы выявления, изучения и сохранения культовых комплексов с каменными крестами: по материалам работ 2016-2017 гг. в Ленинградской области