We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3749
    • 24,544 Posts
    Quote from: crecorn at Mar 24, 2015, 09:22 AM
    <link rel="stylesheet" href="[[++ce.assets_url]]css/base.css">
    <link rel="stylesheet" href="[[++ce.assets_url]]css/gazoobie.css">
    


    So I have this in the head. Do I put the code in the gazoobie.config file and do one for each css and js file?

    If you do it that way, the user either won't have the ce.assets_url System Setting, or they will and it will be wrong for their machine (because they don't have the files in the development location). That's why I do it with regClient*() in the snippet or plugin code.



      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
      • 3749
      • 24,544 Posts
      Quote from: crecorn at Mar 24, 2015, 01:07 PM
      OK an additional question only because I don't know php.

      On a clean install I have a few resources installed but when I update I don't want to update or add the resources. What is the best way to handle this?

      There are two ways to go with this, neither very satisfactory.

      If you are installing the resources in a resolver, you can just put the install code in the Install but not the Update section of the resolver.

      If they are being installed as part of the main package, you can find the resource section of build.transport.php, and change this line:

       xPDOTransport::UPDATE_OBJECT => true,


      (line 418 in my version) to:

       xPDOTransport::UPDATE_OBJECT => false,


      That way the resources won't be updated if they exist. The down side of this method is that the resources then won't be removed if you uninstall the package. You have to remove them manually in the uninstall section of a resolver. This has to do with how Package Manager works and I have no control over it. I've filed a feature request to separate the two functions (Update and remove on uninstall), so someday maybe this won't be a problem.

        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
        • 36573
        • 173 Posts
        Quote from: BobRay at Mar 24, 2015, 11:29 PM

        If you do it that way, the user either won't have the ce.assets_url System Setting, or they will and it will be wrong for their machine (because they don't have the files in the development location). That's why I do it with regClient*() in the snippet or plugin code.

        That's what I was thinking. So where does this code go? I'm just not following, sorry.

        $cssFile = $this->modx->getOption('ce.assets_url', null,
            MODX_ASSETS_URL . 'components/classextender/') . 'css/classextender.css?v=' . $this->version;
         
        $this->modx->regClientCSS($cssFile);
          Everything I know I learned on the internet. Saved me thousands in College tuition,
          • 3749
          • 24,544 Posts
          It goes at the top of a snippet or plugin in your extra (and you need to set $version to something above that). BTW, this is just an example from the ClassExtender code, your code will be different and will refer to a different System Setting and CSS file.
            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
            • 36573
            • 173 Posts
            Due to my limited understanding of php I simplified. Is there any reason why this is a bad idea?

            This is my snippet:
            $cssFile = $modx->getOption('gz.asset_url',null, MODX_ASSETS_URL . 'components/gazoobie/');
            
            return $cssFile;


            This is my js & CSS link:
            <link rel="stylesheet" href="[[getasset_url]]css/base.css">
            <script src="[[getasset_url]]js/modernizr.js"></script>


            This way, I figured, I could use the [[getasset_url]] in other places also. It works. Is there any reason why this is a bad idea?
              Everything I know I learned on the internet. Saved me thousands in College tuition,
              • 3749
              • 24,544 Posts
              That certainly would work. The reason I don't do it that way is that then whoever installs the extra has to use your Template or edit their
              Template on any page that uses the extra. For some extras, that would be fine, but for many of mine, it would be a pain for the user.

              This would have the same effect, but with nothing required but the snippet tag:

              $assetsPath = $modx->getOption('gz.asset_url',null, MODX_ASSETS_URL . 'components/gazoobie/');
              $cssFile = $assetsPath . 'css.base.css';
              $jsFile = $assetsPath . 'js/modernizr.js';
              
              $modx->regClientCSS($cssFile);
              $modx->regClientStartupScript($jsFile);
              return '';


              Most of my extras are snippets or plugins, so I just add code like that near the top.
                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
                • 36573
                • 173 Posts
                I see what you're saying. Because what I'm working on is a base site structure install for myself it's not as big a deal. I'm starting to get a better understanding how these transport packages are created and work. Thanks for the help.

                How do you list multiple css and js files in the code above? and if I only wanted to install and not update a select file how would I do that?

                Where do you suggest I go to learn PHP? (so I don't have to bug you as much)
                  Everything I know I learned on the internet. Saved me thousands in College tuition,
                  • 3749
                  • 24,544 Posts
                  There are lots of PHP tutorials on the web. There's also a PHP primer that I think is pretty good in the Appendix of my book. wink

                  Multiple files is easy:

                  $cssFile = $assetsPath . 'css/base.css';
                  $cssFile2 = $assetsPath . 'css/something.css';
                  
                  $jsFile = $assetsPath . 'js/modernizr.js';
                  $jsFile2 = $assetsPath . 'js/something.js';
                   
                  $modx->regClientCSS($cssFile);
                  $modx->regClientCSS($cssFile2);
                  
                  $modx->regClientStartupScript($jsFile);
                  $modx->regClientStartupScript($jsFile2);
                  
                  return '';
                  



                  Installing a file but not upgrading can be tricky, especially if there are some files you want to update and some you don't. I've never done it.

                  This section of build.transport.php installs the files:

                  $vehicle = $builder->createVehicle($category,$attr);
                  $vehicle->resolve('file',array(
                          'source' => $sources['source_core'],
                          'target' => "return MODX_CORE_PATH . 'components/';",
                      ));
                      $vehicle->resolve('file',array(
                          'source' => $sources['source_assets'],
                          'target' => "return MODX_ASSETS_PATH . 'components/';",
                      ));
                  
                  $builder->putVehicle($vehicle);


                  If, for example, you don't want to update any files in the assets directory, I think this would do it:

                  $vehicle = $builder->createVehicle($category,$attr);
                  $vehicle->resolve('file',array(
                          'source' => $sources['source_core'],
                          'target' => "return MODX_CORE_PATH . 'components/';",
                          xPDOTransport::PRESERVE_PREEXISTING => true;  // Adding this should preserve pre-existing files
                      ));
                      $vehicle->resolve('file',array(
                          'source' => $sources['source_assets'],
                          'target' => "return MODX_ASSETS_PATH . 'components/';",
                      ));
                  
                  $builder->putVehicle($vehicle);


                  If there are particular files you don't want to upgrade, I think you'd have to use a validator that runs early in the install and copy them somewhere safe (or rename them), then use a resolver that runs after the file resolvers to copy them back or delete the new one and rename the old one to its original name.

                    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
                    • 36573
                    • 173 Posts
                    After moving a hand full of packages to a subpackages folder. I got this error when running an export or build. It's repeated along with some slight variations about 40-50 times. I had also moved some code from templates and chunks to linked static files. I did a test install and all the packages were there but the links to the static file did not carry over.

                    [2015-03-27 21:15:31] (ERROR @ /index.php)
                    
                    Error HY000 executing query: SELECT `modSnippet`.`id` AS `modSnippet_id`, `modSnippet`.`source` AS `modSnippet_source`, `modSnippet`.`property_preprocess` AS `modSnippet_property_preprocess`, `modSnippet`.`name` AS `modSnippet_name`, `modSnippet`.`description` AS `modSnippet_description`, `modSnippet`.`editor_type` AS `modSnippet_editor_type`, `modSnippet`.`category` AS `modSnippet_category`, `modSnippet`.`cache_type` AS `modSnippet_cache_type`, `modSnippet`.`snippet` AS `modSnippet_snippet`, `modSnippet`.`locked` AS `modSnippet_locked`, `modSnippet`.`properties` AS `modSnippet_properties`, `modSnippet`.`moduleguid` AS `modSnippet_moduleguid`, `modSnippet`.`static` AS `modSnippet_static`, `modSnippet`.`static_file` AS `modSnippet_static_file`, `Source`.`id` AS `Source_id`, `Source`.`name` AS `Source_name`, `Source`.`description` AS `Source_description`, `Source`.`class_key` AS `Source_class_key`, `Source`.`properties` AS `Source_properties`, `Source`.`is_stream` AS `Source_is_stream` FROM `modx_site_snippets` AS `modSnippet` LEFT JOIN `modx_media_sources` `Source` ON `modSnippet`.`source` = `Source`.`id` WHERE `modSnippet`.`name` = ? ORDER BY `modSnippet`.`id` ASC  - Array
                    (
                        [0] => HY000
                        [1] => 2006
                        [2] => MySQL server has gone away
                    )
                      Everything I know I learned on the internet. Saved me thousands in College tuition,
                      • 3749
                      • 24,544 Posts
                      There might be a problem with your MySQL server. That SELECT statement is part of MODX, not MyComponent.

                      IIRC, MyComponent assumes that you don't want to force static elements on users who may not want them, so it unsets the static field when building the package. It's also very difficult to set them up since they interact with the user's Media Sources and they can vary.
                        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