Where To Put Stuff

Because MODx puts as few restrictions on web designers as possible, the official answer to this question is: anywhere you want. That said, there are some typical file locations for user files that will make them easier to find and safe from upgrades. If you use this organization, it will also help you know where to look to find the files of third-party components.

Generally, stuff that needs to be accessed by URL, like JS and CSS files, goes under the assets directory. The files will be available by URL even if you move other directories and MODx will leave them alone during upgrades.

These directories: assets/js and assets/css, are common locations for JavaScript and CSS files, but you're free to organize them any way you want, so you can put them in separate subdirectories under that, organized by function, if you like.

If they are in those directories, you can refer to them in code with something like this:

    $url = MODX_ASSETS_PATH . 'css/myfile.css';
    $url = MODX_ASSETS_PATH . 'js/myfile.js';

If the files are tied to a specific snippet or plugin, the convention is to put them in these locations:

    assets/components/component_name/css/
    assets/components/component_name/js/

Then, you refer to them like this:

    $url = MODX_ASSETS_PATH .  'components/component_name/css/myfile.css';
    $url = MODX_ASSETS_PATH .  'components/component_name/js/myfile.js';

Note that all the MODx path and URL constants always end with a slash so your part of the string shouldn't start with one.

For files that don't need to be accessed by URL (e.g. text, php, or data files), the convention in MODx Revolution is the same except that if they are tied to a snippet or plugin, they should go under:

    MODX_CORE_PATH . 'components/component_name/

along with any component files (e.g., class files, readme.txt, changelog.txt, lexicon files, etc.). See the installed directories of the FormIt or Login packages for a typical structure for those files. Most add-on components will have a directory under core/components/component_name and assets/components/component_name, with only the files that need to be accessed by URL under the assets directory.

 

My book, MODX: The Official Guide - Digital Edition is now available here. The paper version of the book is available from Amazon.

If you have the book and would like to download the code, you can find it here.

If you have the book and would like to see the updates and corrections page, you can find it here.

MODX: The Official Guide is 772 pages long and goes far beyond this web site in explaining beginning and advanced MODX techniques. It includes detailed information on:

  • Installing MODX
  • How MODX Works
  • Working with MODX resources and Elements
  • Using Git with MODX
  • Using common MODX add-on components like SPForm, Login, getResources, and FormIt
  • MODX security Permissions
  • Customizing the MODX Manager
  • Using Form Customization
  • Creating Transport Packages
  • MODX and xPDO object methods
  • MODX System Events
  • Using PHP with MODX

Go here for more information about the book.

Thank you for visiting BobsGuides.com

  —  Bob Ray