We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 34120
    • 236 Posts
    Hi,
    I’m attempting to put together a tansport package that includes all the bits and pieces that I generally create whenever I setup a website with MODx: Templates, Wayfinder, a few chunks and TVs and a basic css file. I’ve been referring to this tutorial Creating a 3rd Party Component Build Script and I’m struggling a little and hope someone could clarify a few points. I’m also new to using SVN so this probably isn’t helping.

    My first question is regarding directory structure and source files. I’ve setup my directory as explained in the tutorial. I’ve also looked at using the component-template structure. Some of the code from this template differs from that of the tutorial. Which is the latest?

    Secondly, do I build my component within a MODx installation or outside as a standalone?

    That’s it for now, any advice much appreciated and any other tips or suggested resources would be great.
    Thanks
      • 28215
      • 4,149 Posts
      Quote from: rf9 at May 04, 2010, 07:20 AM

      I’m attempting to put together a tansport package that includes all the bits and pieces that I generally create whenever I setup a website with MODx: Templates, Wayfinder, a few chunks and TVs and a basic css file. I’ve been referring to this tutorial Creating a 3rd Party Component Build Script and I’m struggling a little and hope someone could clarify a few points. I’m also new to using SVN so this probably isn’t helping.

      My first question is regarding directory structure and source files. I’ve setup my directory as explained in the tutorial. I’ve also looked at using the component-template structure. Some of the code from this template differs from that of the tutorial. Which is the latest?
      Actually, component-template is a bit outdated. I recommend looking at doodles, which is a good demo component.



      Secondly, do I build my component within a MODx installation or outside as a standalone?
      What do you mean by this? Do you mean where your files are located, or where they are run?

      I find it easiest to build it outside the file path of MODx, and add 2 System Settings to tell MODx where the files are. For example, with quip, i have "quip.core_path" and "quip.assets_url". The first points to the directory where the core dir (/workspace/quip/trunk/core/components/quip/) is, and the second points to the URL of the (/workspace/quip/trunk/assets/components/quip/) directory (i’ve put my 3PCs in a ’workspace’ directory, which is web accessible in my localhost via http://localhost/workspace/). Then my component uses those settings to tell itself where its files are. All the snippets have this as their first line:

      $quip = $modx->getService('quip','Quip',$modx->getOption('quip.core_path',null,$modx->getOption('core_path').'components/quip/').'model/quip/',$scriptProperties);
      if (!($quip instanceof Quip)) return '';
      

      The Quip class is a base class that has all the path info, etc. The Doodles class I stated above does the same. Note that this first getService call automatically instantiates a Quip class instance for me as well. It passes 2 arguments, $modx and $scriptProperties (an array of properties passed to the snippet). Note how it also checks to see if the quip.class.php file is in the ’quip.core_path’ place before checking the default MODX_CORE_PATH.’components/quip/’ location.

      This is good in a couple ways - one, it allows me to do development straight from my SVN checkout of Quip (or whatever 3PC), as the files are outside the MODx webroot and are ’checked out’ by SVN. So I can work on Quip, and then immediately commit. (I’ll be speaking on this process at modxpo, btw.)

      Then, in my modx install, I use an ’include’ snippet, which is:

      $o = ''; $f = $scriptProperties['file'];
      if (file_exists($f)) { $o = include $f; }
      return $o;
      


      Then in the Resources where I put the snippets that I’m developing:

      [[!include? &file=`[[++quip.core_path]]snippets/snippet.quip.php`]]
      

      I can also pass any other parameters to the Quip snippet in the include snippet call (as it will just pass them through the include). This allows me to develop Quip straight from outside the webroot.

      Then, once I’m done building Quip, I build the Transport Package, and install it on another MODx install (/modxtest/, on mine), that is empty. This is where I test the Transport Package and see if it works correctly, and if the snippets work well outside my dev environment.

      This workflow allows me to quickly and easily develop 3PCs.

      Again, I’ll be speaking more on this workflow at MODxpo, but that’s basically what I do, and I’ve found it to be a rapid and efficient workflow.
        shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
        • 34120
        • 236 Posts
        Thanks for the reply splittingred, I’ll need to read over your post a few times but I think I’m on the right path. I have my component setup based on the Doodles template and I have the MODX_BASE_PATH pointing to my ’modxtest’ install. This all seems to be working, zip is being created and I can install this as a package.

        Next I need to look at putting all my snippets, chunks and other bits and pieces into the package, not sure at this stage how to do this.

        Good luck with MODxpo, sounds good! Will any of it be recorded? I’m in the UK smiley
          • 28215
          • 4,149 Posts
          Yes, I think we’ll have some sort of recording going on there at some level. Not sure on the details, but we’ll definitely let you guys who couldn’t make it know.
            shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
            • 34120
            • 236 Posts
            Nice, I will look out for it.

            I seem to be making some progress with this package now. I’ve got it packing up snippets and chunks so it’s on to templates next.

            I was hoping to package a couple of existing components in, Wayfinder and Formit. I seem to remember reading that this was possible? I may not bother with this depending how tricky it is. It doesn’t really take too long to download and install these individually.

              • 28215
              • 4,149 Posts
              Quote from: rf9 at May 05, 2010, 11:04 AM

              I was hoping to package a couple of existing components in, Wayfinder and Formit. I seem to remember reading that this was possible? I may not bother with this depending how tricky it is. It doesn’t really take too long to download and install these individually.

              It’s definitely possible. See the MODx Sample Site build code here: http://svn.modxcms.com/svn/modx-components/samplesites/modxss/trunk/_build/

              That said, if you can get away with not packaging them in, it does make it easier, since you dont have to resolve dependencies.
                shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
                • 34120
                • 236 Posts
                Thanks, that link is a great help, it also answers my next question about TVs. I’m going to leave the components thing for now. Anyway, I think I’ve got the hang of this now (hopefully)

                Thanks again for your time and help splittingred, much appreciated!
                  • 34120
                  • 236 Posts
                  I’ve just been looking at and comparing the modxss build code with the Doodles code. I’ve noticed a few differences and wondered if one of them was a preferred and newer method. The modxss doesn’t contain a ’core’ directory and all the elements are stored in the ’_build/data’ directory. The Doodles build contains a ’core’ directory which is home to the elements, models, controllers etc. There also a few minor differences in the code eg. the modxss uses flush():
                  $modx->log(modX::LOG_LEVEL_INFO,'Adding in system settings.'); flush();

                  Both work fine so I suppose it isn’t massively important but I’m a little curious about the differences.
                    • 28215
                    • 4,149 Posts
                    MODxSS is a special case; it overwrites data (including any content you might have had), and so it’s not recommended to follow it’s advice (unless you’re building a sample site).

                    Doodles is by far and away the best example component to go with, as it’s the most recent.
                      shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
                      • 34120
                      • 236 Posts
                      It’s been a while since I touched this so I’m a little rusty. I’m making some changes to my component and I want to create a CSS file in the modx assets directory (not in the component directory). I’ve got this working by adding the following to my build script.
                      $vehicle->resolve('file',array(
                          'source' => $sources['site_css'],
                          'target' => "return MODX_ASSETS_PATH;",
                      ));

                      The problem is this file will be overwritten every time the package is upgraded. Is there a way around this?
                      I suppose the idea is that the CSS file would only be created on the first install.