We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 15914
    • 145 Posts
    Is there a way I can declare a variable that can be used in different snippets, plugins, etc? I want to share just one value that is defined once in one place. Any ideas?

    Thanks in advance.
      Kunal Kapoor
      Technical Director
      Limesharp Internet Limited - Effective, Functional, Standards Compliant

      IRC Nick: KingKoopa
      Skype ID: KingKoopa16
      • 15914
      • 145 Posts
      No worries, I found my answer... of sorts: http://modxcms.com/forums/index.php/topic,1839.0.html

      Anyone know of a better way?
        Kunal Kapoor
        Technical Director
        Limesharp Internet Limited - Effective, Functional, Standards Compliant

        IRC Nick: KingKoopa
        Skype ID: KingKoopa16
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        You could create a plugin that sets $modx->documentObject[’myVariable’] = ’myValue’ and set it to use the onWebPageInit (or whichever one of those events would work) then you can just access it wherever you need it.
          Studying MODX in the desert - http://sottwell.com
          Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
          Join the Slack Community - http://modx.org
          • 15914
          • 145 Posts
          That’s better! That’s what I need! Thanks Susan.
            Kunal Kapoor
            Technical Director
            Limesharp Internet Limited - Effective, Functional, Standards Compliant

            IRC Nick: KingKoopa
            Skype ID: KingKoopa16
            • 28042 ☆ A M B ☆
            • 24,524 Posts
            you might need to fiddle with which event to use; I’m a little hazy on just where these get triggered.
              Studying MODX in the desert - http://sottwell.com
              Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
              Join the Slack Community - http://modx.org
              • 22303 MODX Staff
              • 10,725 Posts
              You can also use the placeholder technique you found in that link in a plugin in the OnWebPageInit event as well. To insure the placeholder value you want to get back is available before the page is even loaded, cached or not.

              Oh, and I wouldn’t use the documentObject to do it. That’s what palceholders are for, adding additional, custom data to a request. Modifying the core documentObject array could have potential consequences and might not be a compatible way of approaching the problem in future releases.
                • 15914
                • 145 Posts
                Quote from: OpenGeek at Feb 19, 2006, 02:29 PM

                Oh, and I wouldn’t use the documentObject to do it. That’s what palceholders are for, adding additional, custom data to a request. Modifying the core documentObject array could have potential consequences and might not be a compatible way of approaching the problem in future releases.

                Placeholders it is then! Thanks a lot team.
                  Kunal Kapoor
                  Technical Director
                  Limesharp Internet Limited - Effective, Functional, Standards Compliant

                  IRC Nick: KingKoopa
                  Skype ID: KingKoopa16
                  • 28042 ☆ A M B ☆
                  • 24,524 Posts
                  Didn’t know placeholders were so flexible and powerful. Definitely better than playing around with the core systems.
                    Studying MODX in the desert - http://sottwell.com
                    Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                    Join the Slack Community - http://modx.org
                    • 32241
                    • 1,495 Posts
                    Another solution will be to use $_GLOBAL[’your_var_name’]

                    But you need to make sure that there is no global var with that name yet, and make the name as unique as possible.
                      Wendy Novianto
                      [font=Verdana]PT DJAMOER Technology Media
                      [font=Verdana]Xituz Media
                      • 15914
                      • 145 Posts
                      Quote from: Djamoer at Feb 19, 2006, 03:05 PM

                      Another solution will be to use $_GLOBAL[’your_var_name’]

                      But you need to make sure that there is no global var with that name yet, and make the name as unique as possible.

                      Perhaps by using a prefix for MY variables. e.g. $_GLOBAL[’kk_your_var_name’].
                        Kunal Kapoor
                        Technical Director
                        Limesharp Internet Limited - Effective, Functional, Standards Compliant

                        IRC Nick: KingKoopa
                        Skype ID: KingKoopa16