Magento 2 How to get Cookie value in Block Unicorn Meta Zoo #1: Why another podcast? Announcing the arrival of Valued Associate #679: Cesar ManaraHow to add Cookie Magento 2?How to add filtering to custom table field column in Customers admin grid in Magento2?I created a custom module ,but getting error, not able to figure out what the error is about. How to get out of this error?main.CRITICAL: Plugin class doesn't existMagento 2: How to override newsletter Subscriber modelMagento 2.1 Create a filter in the product grid by new attributeMagento 2 Add new field to Magento_User admin formMagento offline custom Payment method with drop down listMagento 2 Create dynamic array From different Model Collection to use in multi select in gridMagento 2.3 Can't view module's front end page output?Magento 2 How to remove price filter from category if module is enable?

Is Bran literally the world's memory?

c++ diamond problem - How to call base method only once

What is /etc/mtab in Linux?

Implementing 3DES algorithm in Java: is my code secure?

Raising a bilingual kid. When should we introduce the majority language?

Second order approximation of the loss function (Deep learning book, 7.33)

Is a 5 watt UHF/VHF handheld considered QRP?

Is Electric Central Heating worth it if using Solar Panels?

How to open locks without disable device?

How to avoid introduction cliches

Trumpet valves, lengths, and pitch

Could moose/elk survive in the Amazon forest?

Retract an already submitted recommendation letter (written for an undergrad student)

How to keep bees out of canned beverages?

Why is this method for solving linear equations systems using determinants works?

std::is_constructible on incomplete types

Why didn't the Space Shuttle bounce back into space as many times as possible so as to lose a lot of kinetic energy up there?

Is Diceware more secure than a long passphrase?

I preordered a game on my Xbox while on the home screen of my friend's account. Which of us owns the game?

What is the term for a person whose job is to place products on shelves in stores?

How to not starve gigantic beasts

As an international instructor, should I openly talk about my accent?

Does Feeblemind produce an ongoing magical effect that can be dispelled?

What do you call the part of a novel that is not dialog?



Magento 2 How to get Cookie value in Block



Unicorn Meta Zoo #1: Why another podcast?
Announcing the arrival of Valued Associate #679: Cesar ManaraHow to add Cookie Magento 2?How to add filtering to custom table field column in Customers admin grid in Magento2?I created a custom module ,but getting error, not able to figure out what the error is about. How to get out of this error?main.CRITICAL: Plugin class doesn't existMagento 2: How to override newsletter Subscriber modelMagento 2.1 Create a filter in the product grid by new attributeMagento 2 Add new field to Magento_User admin formMagento offline custom Payment method with drop down listMagento 2 Create dynamic array From different Model Collection to use in multi select in gridMagento 2.3 Can't view module's front end page output?Magento 2 How to remove price filter from category if module is enable?



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








0















I didn't get the Cookie Value in any block or phtml file.



This is the code:




Extra.php (Block File)




<?php
namespace WebsourceQuotationBlock;
class Extra extends BaseBlock
const COOKIE_NAME = 'test';

protected $_cookieManager;

public function __construct(
Context $context,MagentoFrameworkStdlibCookieManagerInterface $cookieManager
)
$this->_cookieManager = $cookieManager;
parent::__construct($context);


public function getCookieData()
$result = $this->_cookieManager->getCookie(self::COOKIE_NAME);
return $result;





extra.phtml




$getCookieData = $block->getCookieData();


All other normal functions are working of block for phtml file only on getCookieData() function return null value.



Thanks in Advance for investing your time.










share|improve this question














bumped to the homepage by Community 5 hours ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.





















    0















    I didn't get the Cookie Value in any block or phtml file.



    This is the code:




    Extra.php (Block File)




    <?php
    namespace WebsourceQuotationBlock;
    class Extra extends BaseBlock
    const COOKIE_NAME = 'test';

    protected $_cookieManager;

    public function __construct(
    Context $context,MagentoFrameworkStdlibCookieManagerInterface $cookieManager
    )
    $this->_cookieManager = $cookieManager;
    parent::__construct($context);


    public function getCookieData()
    $result = $this->_cookieManager->getCookie(self::COOKIE_NAME);
    return $result;





    extra.phtml




    $getCookieData = $block->getCookieData();


    All other normal functions are working of block for phtml file only on getCookieData() function return null value.



    Thanks in Advance for investing your time.










    share|improve this question














    bumped to the homepage by Community 5 hours ago


    This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.

















      0












      0








      0








      I didn't get the Cookie Value in any block or phtml file.



      This is the code:




      Extra.php (Block File)




      <?php
      namespace WebsourceQuotationBlock;
      class Extra extends BaseBlock
      const COOKIE_NAME = 'test';

      protected $_cookieManager;

      public function __construct(
      Context $context,MagentoFrameworkStdlibCookieManagerInterface $cookieManager
      )
      $this->_cookieManager = $cookieManager;
      parent::__construct($context);


      public function getCookieData()
      $result = $this->_cookieManager->getCookie(self::COOKIE_NAME);
      return $result;





      extra.phtml




      $getCookieData = $block->getCookieData();


      All other normal functions are working of block for phtml file only on getCookieData() function return null value.



      Thanks in Advance for investing your time.










      share|improve this question














      I didn't get the Cookie Value in any block or phtml file.



      This is the code:




      Extra.php (Block File)




      <?php
      namespace WebsourceQuotationBlock;
      class Extra extends BaseBlock
      const COOKIE_NAME = 'test';

      protected $_cookieManager;

      public function __construct(
      Context $context,MagentoFrameworkStdlibCookieManagerInterface $cookieManager
      )
      $this->_cookieManager = $cookieManager;
      parent::__construct($context);


      public function getCookieData()
      $result = $this->_cookieManager->getCookie(self::COOKIE_NAME);
      return $result;





      extra.phtml




      $getCookieData = $block->getCookieData();


      All other normal functions are working of block for phtml file only on getCookieData() function return null value.



      Thanks in Advance for investing your time.







      magento2 cookie






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jan 3 '18 at 12:13









      Rajan SoniRajan Soni

      585524




      585524





      bumped to the homepage by Community 5 hours ago


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







      bumped to the homepage by Community 5 hours ago


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.






















          1 Answer
          1






          active

          oldest

          votes


















          0














          If you want to use block, you could try this way How to add Cookie Magento 2?




          If you want to use js only, you could make use of mage/cookies in template file like below



          Set the cookies



          <script>
          require([
          'jquery',
          'mage/cookies'
          ], function ($)
          $.cookie('cookie_name', 'value', path: '/' );//Set the cookies
          );
          </script>



          If you want get the value from another page, notice the path setting path: '/' !



          Because cookies are only accessible to the specified path and any subpaths , more discussion about this you could see here Cookie path and its accessibility to subfolder pages.




          Get the cookies



          <script>
          require([
          'jquery',
          'mage/cookies'
          ], function ($)
          var temp = $.cookie('cookie_name');//Get the cookies
          );
          </script>





          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%2f207910%2fmagento-2-how-to-get-cookie-value-in-block%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









            0














            If you want to use block, you could try this way How to add Cookie Magento 2?




            If you want to use js only, you could make use of mage/cookies in template file like below



            Set the cookies



            <script>
            require([
            'jquery',
            'mage/cookies'
            ], function ($)
            $.cookie('cookie_name', 'value', path: '/' );//Set the cookies
            );
            </script>



            If you want get the value from another page, notice the path setting path: '/' !



            Because cookies are only accessible to the specified path and any subpaths , more discussion about this you could see here Cookie path and its accessibility to subfolder pages.




            Get the cookies



            <script>
            require([
            'jquery',
            'mage/cookies'
            ], function ($)
            var temp = $.cookie('cookie_name');//Get the cookies
            );
            </script>





            share|improve this answer



























              0














              If you want to use block, you could try this way How to add Cookie Magento 2?




              If you want to use js only, you could make use of mage/cookies in template file like below



              Set the cookies



              <script>
              require([
              'jquery',
              'mage/cookies'
              ], function ($)
              $.cookie('cookie_name', 'value', path: '/' );//Set the cookies
              );
              </script>



              If you want get the value from another page, notice the path setting path: '/' !



              Because cookies are only accessible to the specified path and any subpaths , more discussion about this you could see here Cookie path and its accessibility to subfolder pages.




              Get the cookies



              <script>
              require([
              'jquery',
              'mage/cookies'
              ], function ($)
              var temp = $.cookie('cookie_name');//Get the cookies
              );
              </script>





              share|improve this answer

























                0












                0








                0







                If you want to use block, you could try this way How to add Cookie Magento 2?




                If you want to use js only, you could make use of mage/cookies in template file like below



                Set the cookies



                <script>
                require([
                'jquery',
                'mage/cookies'
                ], function ($)
                $.cookie('cookie_name', 'value', path: '/' );//Set the cookies
                );
                </script>



                If you want get the value from another page, notice the path setting path: '/' !



                Because cookies are only accessible to the specified path and any subpaths , more discussion about this you could see here Cookie path and its accessibility to subfolder pages.




                Get the cookies



                <script>
                require([
                'jquery',
                'mage/cookies'
                ], function ($)
                var temp = $.cookie('cookie_name');//Get the cookies
                );
                </script>





                share|improve this answer













                If you want to use block, you could try this way How to add Cookie Magento 2?




                If you want to use js only, you could make use of mage/cookies in template file like below



                Set the cookies



                <script>
                require([
                'jquery',
                'mage/cookies'
                ], function ($)
                $.cookie('cookie_name', 'value', path: '/' );//Set the cookies
                );
                </script>



                If you want get the value from another page, notice the path setting path: '/' !



                Because cookies are only accessible to the specified path and any subpaths , more discussion about this you could see here Cookie path and its accessibility to subfolder pages.




                Get the cookies



                <script>
                require([
                'jquery',
                'mage/cookies'
                ], function ($)
                var temp = $.cookie('cookie_name');//Get the cookies
                );
                </script>






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jan 5 '18 at 10:49









                Key ShangKey Shang

                1,7111235




                1,7111235



























                    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%2f207910%2fmagento-2-how-to-get-cookie-value-in-block%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

                    Nidaros erkebispedøme

                    Birsay

                    Was Woodrow Wilson really a Liberal?Was World War I a war of liberals against authoritarians?Founding Fathers...