We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 577
    • 132 Posts
    Does anyone know if I can and if so how, describe default property values for an element (ie: chunk, snippet, template, plugin) within the config array for MyComponent?

    I know I can create the properties on the element in modx and then Export Objects to get the properties written to the build but that means the properties live in modx and not in the model that describes the component. Thus the properties never get into git when the config is committed.

    My hope is that the config always fully describes my component so that another dev could create their own build env by simply processing the latest config.
      "One of these days I will get around to my own website... Its only been about 12 years... maybe tomorrow smiley"
      • 3749
      • 24,544 Posts
      It's a good question. At present, I think the only option is to create them in MODX, though I haven't actually tried putting them in the config file -- I guess it could work, though I don't know offhand whether they would have to be in the form of an array or a JSON string -- probably an array.

        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
        • 577
        • 132 Posts
        I will give it another try in the config placing it as an array under the snippet/chunk array with a key of "properties" and see what happens. I know I have tried this in both JSON and Array formats with no luck but never hurts to try again.

          "One of these days I will get around to my own website... Its only been about 12 years... maybe tomorrow smiley"
          • 3749
          • 24,544 Posts
          I should have mentioned before that you can create a properties file in the _build/data/properties/ directory. If it's named correctly, the properties will be imported when you run ImportObjects.

          For a snippet called mysnippet, for example, the filename would be:

          properties.mysnippet.snippet.php


          Here's the form of the properties file:

          $properties = array (
          
            'package' =>  array (
                'name' => 'package',
                'desc' => 'ce.package_desc',
                'type' => 'textfield',
                'options' => array (),
                'value' => '',
                'lexicon' => 'classextender:properties',
                'area' => '',
            ),
          
            'class' => array (
                'name' => 'class',
                'desc' => 'ce.class_desc',
                'type' => 'textfield',
                'options' => array (),
                'value' => '',
                'lexicon' => 'classextender:properties',
                'area' => '',
            ),
          
            'parentObject' => array (
                'name' => 'parentObject',
                'desc' => 'ce.parent_object_desc',
                'type' => 'textfield',
                'options' => array (),
                'value' => '',
                'lexicon' => 'classextender:properties',
                'area' => '',
            ),
          }


          FWIW, I think it's much easier to create the properties in MODX and export them, especially if you have complex options. The properties file will still be a reference for them. You can put it under version control and also edit it and import.
            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
            • 577
            • 132 Posts
            Thanks BobRay,

            I will consider this. Maybe I need to adjust the way I use MyComponents. Currently I leave the _build out of the repo with the idea being that a dev can checkout the repo and hook up the config, then Bootstrap and have the _build directory created with all the latest config data in it.

            Being that I am developing and not just packaging something that is for the most part already developed I tend to throw the _build away alot so that everything can get rebuild. MyC does a great job of not overwriting but many times that is what I want... blowing out _build is a easy way to do that.
              "One of these days I will get around to my own website... Its only been about 12 years... maybe tomorrow smiley"