We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 10473
    • 44 Posts
    Does anyone have a good example of a well written MODx module that’s not too complicated, but uses renderFormElement() and other standard MODx functions?

    I’m making my first ever module, and am having trouble with implementing a good simple clean MODx module.

    I take it that I owuld be better off using standard files like header.inc.php, and so on, but when I use them I get all sorts of errors.
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      You might want to check out the tutorials I wrote on making a database management module; see my sig for the guest manager user login.
        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
        • 10473
        • 44 Posts
        Thanks for the link, the article was most interesting. So what you recommend is to just use ordinary PHP for the modules.

        I am doing that on my current modules, but what I would prefer to do is use all the crunchy MODx goodness, like the header.inc.php, and footer.inc.php, as well as being able to use standard MODx date and rich text controls without having to cut and paste a ton of HTML from one place to another.

        That said, I would be very interested in seeing your database.php file.
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          Each article has the relevant files available for download. The download links are in the left sidebar of the article pages.

          The first article explains how to make a module look like the default MODx manager theme:
          There are two files that the MODx Manager uses for all of its main frames; manager/includes/header.inc.php and manager/includes/footer.inc.php. In the case of the module management frame, it uses the manager/actions/static/modules.static.action.php file. I "borrowed" the parts from these files that I wanted to provide the look-and-feel of the module. Since it’s a module, and not a part of the Manager, the variables (such as which manager theme is being used by the site) are not available, but these values can be retrieved through the $modx object, which is available to modules. So instead of the variables you need to use $modx->config[’manager_theme’] in the links for the css files.
          <link rel="stylesheet" type="text/css" href="media/style/<?php echo $modx->config[’manager_theme’]; ?>/style.css" />

          Do the same for links to the icons.
            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
            • 10473
            • 44 Posts
            Thanks for the information, it answered my question fully.

            Does anyone know if there will come a time when we can use these modules without a load of errors popping up? It would save a ton of time.
              • 27376
              • 576 Posts
              Try adding [tt]global $variable;[/tt] to the top of your module for each undefined variable error that pops up.

              global $modx_charset, $manager_theme;


              There’s others that will show up, just continue the list and eventually you’ll get rid of all of them. Keep in mind this method is only needed if you intend to use the MODx provided header and footer files. Sottwell’s method is much easier and should be used instead.
                • 33372
                • 1,611 Posts
                As I understand it, modules as such will not exist as of 0.97 (a new improved system will replace the concept). But they can be made to work now without errors, albeit without a full serving of MODx crunchy goodness. If you’re having specific problems that you can’t resolve, post your code so that we can try to help you figure them out.
                  "Things are not what they appear to be; nor are they otherwise." - Buddha

                  "Well, gee, Buddha - that wasn&#39;t very helpful..." - ZAP

                  Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options
                  • 10473
                  • 44 Posts
                  So, probably best to copy sotwells methods now, and learn what the new method is when 0.97 comes out.