We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 8895
    • 76 Posts
    hi fellow modx fans!

    im coding several snippets and many of these contain the same or similar db queries and i also made a function that processes every kind of user inputs.

    now, is there a good and efficient way to include these codes in the different snippets?
    and the other thing would be, when i need the same query for 3 or 4 different snippets - how do i ensure that the db request is only done once yet the result is available for all of the necessary snippets?

    thank you in beforehand grin
      • 10449
      • 956 Posts
      You could create a placeholder. If the placeholder (var) value is empty, run the query, if not, skip it.
        • 8895
        • 76 Posts
        cool, thats an idea - but is there a way i can include the query in the individual snippets?
        with an additional snippet, chunk or so...

        like with standard php u could also make a php file with the query and then include it to the main file, just that here i dont want to place it in a file.

        point is that i want to be able to edit the query at one place and not have to go to X amount of snippets and edit it everywhere - additionally i might forget one and alredy i have bugs ocurring

        cheers
          • 10449
          • 956 Posts
          well, in that case try
          include_once("path/to/your/script.php");

            • 8895
            • 76 Posts
            ye i would know that one too, but i dont want to do it over a file...

            i want to have everything in the modx manager - because depending on where i am i cant access the ftp and in this case i could not edit the file on the server
              • 33372
              • 1,611 Posts
              You can just put the query in a separate snippet and assign the result to a placeholder or a global variable. Then place that snippet before the others on the page. You could probably also do what you want with a TV, a plugin, or PHx...
                "Things are not what they appear to be; nor are they otherwise." - Buddha

                "Well, gee, Buddha - that wasn't very helpful..." - ZAP

                Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options
                • 3749
                • 24,544 Posts
                Quote from: enigma at Nov 08, 2007, 09:06 AM

                ye i would know that one too, but i dont want to do it over a file...

                i want to have everything in the modx manager - because depending on where i am i cant access the ftp and in this case i could not edit the file on the server

                Just so you know, if your host provides a cPanel interface, you can log on to cPanel and use the cPanel file manager, navigate to the file, then open it in an editor. My host provides three different editors to use for remotely editing files (a text editor, and html editor, and a code editor). It’s almost exactly the same amount of work it is to edit them in the MODx manager and sometimes, the host’s editor is better.

                Bob
                  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
                  • 8895
                  • 76 Posts
                  i would have u a good tip if u dont like some editors =)
                  theres a firefox plugin called "its all text"
                  with this u can set an editor for all textboxes,
                  and ive set it so when i press ctrl+e it opens my editor
                  and i can edit nicely, when u then press ctrl+s
                  its saved directly into the textbox ;-)

                  ps. ive got a dedicated host and i dont like cp
                    • 8895
                    • 76 Posts
                    Quote from: ZAP at Nov 08, 2007, 11:12 AM

                    You can just put the query in a separate snippet and assign the result to a placeholder or a global variable. Then place that snippet before the others on the page. You could probably also do what you want with a TV, a plugin, or PHx...

                    how could it do it with a TV? i was thinking about calling a snippet within the page, but i dont like the idea because its not so clear (as i rarely look at the pages) - id preffer a method where i could call up the query code inside the code itsself, then its clear (as im not the only one coding the page)..
                      • 34017
                      • 898 Posts
                      enigma,

                      You could create a checkbox TV that says "if thisTV == checked, the runsnippet".

                      PS - I second, using "its all text"
                        Chuck the Trukk
                        ProWebscape.com :: Nashville-WebDesign.com
                        - - - - - - - -
                        What are TV's? Here's some info below.
                        http://modxcms.com/forums/index.php/topic,21081.msg159009.html#msg1590091
                        http://modxcms.com/forums/index.php/topic,14957.msg97008.html#msg97008