We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 44793
    • 19 Posts
    In Developing an Extra in MODX Revolution, the tutorial discusses using a system setting such as doodles.assets_url to reference a different path for assets during development. It talks about how to reference this setting from PHP (snippets, etc), but I didn't see how to reference it from a page, template or chunk.

    Let's assume the following system setting is set on the dev server (not production):

    • doodles.assets_url: /doodles/assets/components/doodles/

    Would you use something like the following?

    Logo chunk:
    <img src="[[++doodles.assets_url:default=`[[++assets_url]]components/doodles/`]]images/logo.png" alt="Doodles Logo" />
    


    I suppose one could write a snippet to fetch the appropriate assets_url, which would allow the above to be simplified, like so:

    getDoodlesAssetsUrl snippet:
    <?php
    $defaultAssetsUrl = $modx->getOption('assets_url') . 'components/doodles/';
    return $modx->getOption('doodles.assets_url', null, $defaultAssetsUrl);
    

    Simplified logo chunk:
    <img src="[[getDoodlesAssetsUrl]]images/logo.png" alt="Doodles Logo" />
    


    Or, is there a simpler or more standard way?

    Thanks,
    Mike

    This question is related to Dealing with Git when developing Plugins/Extras for MODX.

    [ed. note: mhenry07 last edited this post 12 years, 10 months ago.]
      • 3749
      • 24,544 Posts
      I usually put those kinds of things in their installed locations (in your example, under assets/components/doodles), since they are seldom things you have to edit. Otherwise, your Tpl chunks end up with unnecessary stuff people can't understand unless you edit them all before building the package. Of course they also have to be in the development location in order to be included in the package.

      I do the same thing with lexicon files (core/components/doodles/lexicon), since $modx->lexicon->load() won't accept a path and always uses the namespace's core path.
        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
        • 44793
        • 19 Posts
        Thanks for your reply, Bob.

        Although it isn't the typical [[++assets_url]], it seems like [[getDoodlesAssetsUrl]] would be easy enough to understand. Also, while some assets may not change much during development, some might, like custom javascript and css.

        I suppose depending on whether one is creating an extra meant to be reused or developing for a specific site would affect priorities. Personally, I would prefer to minimize or avoid duplication where possible.

        I suppose other possible options might be to use a script to modify references during the build (like you mentioned) or to write a script that copies assets from the project folder to the modx folder for local testing.
          • 3749
          • 24,544 Posts
          I inject the JS and CSS in code using regClientCSS() and regClientStartupScript(). That way the System Setting applies and they get included from their dev. locations during development.

          My extras so far haven't included any images (except occasionally in the docs). TBH, after writing over 30 MODX extras, I've never encountered your situation except with lexicon files. Imagine it would come into play when creating a MODX template.
            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
            • 44793
            • 19 Posts
            Thanks, those methods look interesting. I found some documentation on them but would like a better understanding. Maybe I'll take a look at the source code.

            In my scenario, I'm actually developing a site rather than an extra, although a lot of the functionality is in one 'component'.
              • 3749
              • 24,544 Posts
              Have you looked at MyComponent? That's what I would use to package a site.

              BTW, there's nothing to stop you from using the real /core and /assets directories as sources in your build script. It's just not a good idea to install the package in the same MODX install where you developed it, but you probably wouldn't want to do that anyway.

                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
                • 44793
                • 19 Posts
                Regarding MyComponent, say if one were to redistribute a package developed using MyComponent, would that package be required to be GPL?

                True, one could use the real core and assets directories with a build script, but wouldn't that make version control trickier?
                  • 3749
                  • 24,544 Posts
                  Quote from: mhenry07 at Nov 25, 2013, 04:02 PM
                  Regarding MyComponent, say if one were to redistribute a package developed using MyComponent, would that package be required to be GPL?

                  Not the package itself, only any GPL files you include in it. You're free to change the license template in MyComponent and use any license you choose (or no license).


                  True, one could use the real core and assets directories with a build script, but wouldn't that make version control trickier?

                  Yes it would. wink

                    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
                    • 44793
                    • 19 Posts
                    Cool, I appreciate your input.

                    Not sure where you're located, but if you're in the U.S. have a great Thanksgiving!
                      • 3749
                      • 24,544 Posts
                      I'm in Florida right now. You too. smiley
                        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