Magento 2 How to get Cookie value in Block Unicorn Meta Zoo #1: Why another podcast? ...

What is it called when you ride around on your front wheel?

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

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

What is the ongoing value of the Kanban board to the developers as opposed to management

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

Is accepting an invalid credit card number a security issue?

Why did C use the -> operator instead of reusing the . operator?

Is a 5 watt UHF/VHF handheld considered QRP?

What is /etc/mtab in Linux?

Justification for leaving new position after a short time

Need of separate security plugins for both root and subfolder sites Wordpress?

Is Electric Central Heating worth it if using Solar Panels?

Expansion//Explosion and Siren Stormtamer

Passing args from the bash script to the function in the script

Seek and ye shall find

What *exactly* is electrical current, voltage, and resistance?

Will I lose my paid in full property

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

Does Mathematica have an implementation of the Poisson Binomial Distribution?

Do I need to protect SFP ports and optics from dust/contaminants? If so, how?

Is this homebrew racial feat, Stonehide, balanced?

Protagonist's race is hidden - should I reveal it?

What is "leading note" and what does it mean to "raise a note"?

Is Bran literally the world's memory?



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 3 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 3 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 3 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 3 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

                    “%fieldName is a required field.”, in Magento2 REST API Call for GET Method Type The Next...

                    How to change City field to a dropdown in Checkout step Magento 2Magento 2 : How to change UI field(s)...

                    變成蝙蝠會怎樣? 參考資料 外部連結 导航菜单Thomas Nagel, "What is it like to be a...