We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37054
    • 93 Posts
    Hey folks,

    Currently working on an extra in which I want to use ExtJS or actually more specifically, ModExt (the countries dropdown) in my setup options form. I figure I would add a div to the script and then use that to house a panel with my various components, countries list included. Question is, how to include the script? I could of course inline the script but that could be messy maintenance-wise so I would prefer another option if possible. Another option would be to just hardcode the options in the select but I am sure there will be other times scripts would be useful - say for validation.

    So is there a preferred way to include scripts? Views and opinions welcome.
      • 18373 ☆ A M B ☆
      • 3,141 Posts
      I guess inline. As a package is installed the files are still in the core dir, so don't think there's a good way to include a script in a setup resolver.

      Oh, and maintenance wise you should be able to script it in a different file and use file_get_contents() to get it into the resolver when you need it?
        Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

        Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
        • 37054
        • 93 Posts
        Hmmm, good point, hadn't considered that. Could host the file remotely though and reference that maybe...
          • 18373 ☆ A M B ☆
          • 3,141 Posts
          Maybe, though you'd have to consider cross-domain requests (if any) in that case.
            Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

            Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
            • 37054
            • 93 Posts
            Yeah, won't be any in this case at least - will see if it actually works later - hate inlining scripts - specially in PHP.
              • 37054
              • 93 Posts
              Thinking more about this, I don't like the idea of calling the script remotely. I don't think folk will appreciate having external (untrusted) injections in their manager.

              But, I have a cunning plan.

              I'm going to make a blank package tomorrow and check the working directory that the resolver runs from by having it print it out - that should give me some idea of where to place the js file prior to installation via the validator script and where to call it from during the presentation of the setup options screen. Then I can remove it in the resolver when it has served its purpose.
                • 3749
                • 24,544 Posts
                Brilliant!

                I think you could also include it as a file and remove that file in a second resolver.



                ---------------------------------------------------------------------------------------------------------------
                PLEASE, PLEASE specify the version of MODX you are using . . . PLEASE!
                MODX info for everyone: http://bobsguides.com/modx.html
                  Did I help you? Buy me a beer
                  Get my Book: MODX:The Official Guide
                  MODX info for everyone: http://bobsguides.com/modx.html
                  My MODX Extras
                  Bob's Guides is now hosted at A2 MODX Hosting
                  • 37054
                  • 93 Posts
                  Actually Bob, you were right, I can actually do this simply using a file resolver. Just have to figure out now what governs the size of the setup options window now and I can start assembling things for the next extra smiley [ed. note: freelancewebdev last edited this post 14 years, 7 months ago.]
                    • 18373 ☆ A M B ☆
                    • 3,141 Posts
                    From what I know the resolver will be run by the manager/index.php file, but physically the package directory and its files will be in core/packages... can't count on that being available for including JS from on all setups.

                    Unless you'd somehow manage to first get the files copied over to core/components and assets/components and *then* get it, but I don't think you can sad
                      Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

                      Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
                      • 24865
                      • 289 Posts
                      Quote from: markh at Mar 01, 2012, 07:51 PM
                      From what I know the resolver will be run by the manager/index.php file, but physically the package directory and its files will be in core/packages... can't count on that being available for including JS from on all setups.

                      Unless you'd somehow manage to first get the files copied over to core/components and assets/components and *then* get it, but I don't think you can sad
                      Perhaps creating a file in the cache directory and putting all data from the JS into that? smiley I can think of multiple ways to accomplish this...
                        @MarkGHErnst

                        Developer at Adwise Internetmarketing, the Netherlands.