We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 5811
    • 1,717 Posts

    Which is the better way to implement a default parameter configuration for a snippet ?

    The Property Sets as user-defined collections of properties for an Element seems to be the better choice. But how could I initialize, programmatically, this element for a delivery with the package ?

    Apologize, if the answer is obvious (or somewhere. I have read the documentation but ...), I begin my immersion in Revolution ...
      • 28215
      • 4,149 Posts
      I’ve added an example to the Doodles 3PC of how to add in default properties to a Snippet through the package build script. Just update your Doodles SVN.
        shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
        • 5811
        • 1,717 Posts
        It works. Thanks.

        1/ The properties loaded thru the build script are loaded as "default properties locked".
        Does it mean that if the user would like override the default values he should create an another property set or use the tag notation ?

        2/ With ajaxSearch, the script called by ajax (ajaxSearchPopup.php) load the default parameters by including the default configuration file and get the custom parameters thru javascript. Like this:
          
                include_once AS_PATH . "classes/ajaxSearch.class.inc.php";
        
                define('MODX_API_MODE', true);
        
                include_once (MODX_MANAGER_PATH . '/includes/document.parser.class.inc.php');
                $modx = new DocumentParser;
                $modx->db->connect();
                $modx->getSettings();
                startCMSSession(); 
        
                $default = AS_PATH . 'configs/default.config.php';
        With Revo, how should I implement the snippet context in order to retrieve the complete list of parameters (default and customs (property set and snippet call) ?
        Does it exist an how-to documentation for calling a component thru ajax ?

        3/ Last question: is the correct board regarding questions about how to develop components for Revo, or does is it preferable to post this kind of post in "Module, Plugin & Snippet Creation and Modification" board where posts are not tagged "Revo" ?
          • 22303 MODX Staff
          • 10,725 Posts
          Quote from: coroico at Apr 22, 2010, 10:17 AM

          1/ The properties loaded thru the build script are loaded as "default properties locked".
          Does it mean that if the user would like override the default values he should create an another property set or use the tag notation ?
          Correct; changing the default properties would be a problem on upgrades to the component, since they would be set back to what you provide in the transport package.

          Quote from: coroico at Apr 22, 2010, 10:17 AM

          2/ With ajaxSearch, the script called by ajax (ajaxSearchPopup.php) load the default parameters by including the default configuration file and get the custom parameters thru javascript. Like this:
            
                  include_once AS_PATH . "classes/ajaxSearch.class.inc.php";
          
                  define('MODX_API_MODE', true);
          
                  include_once (MODX_MANAGER_PATH . '/includes/document.parser.class.inc.php');
                  $modx = new DocumentParser;
                  $modx->db->connect();
                  $modx->getSettings();
                  startCMSSession(); 
          
                  $default = AS_PATH . 'configs/default.config.php';
          With Revo, how should I implement the snippet context in order to retrieve the complete list of parameters (default and customs (property set and snippet call) ?
          Does it exist an how-to documentation for calling a component thru ajax ?
          IMO, front-end components should never call external PHP files other than as includes. A MODx Resource should be provided that acts as the AJAX Resource.

          Quote from: coroico at Apr 22, 2010, 10:17 AM

          3/ Last question: is the correct board regarding questions about how to develop components for Revo, or does is it preferable to post this kind of post in "Module, Plugin & Snippet Creation and Modification" board where posts are not tagged "Revo" ?
          Keep it here; we’re going to reorganize soon.
            • 5811
            • 1,717 Posts
            IMO, front-end components should never call external PHP files other than as includes.
            The other solution should be to have the ajax request served by an another snippet, configured on an another (hidden) page.
            But in this case how could I retrieve the default (and custom) parameters used with the inital ajaxSearch snippet call ?

            If the default properties are provided thru the package build, this means I should set up this second snippet with the same default properties. huh why not

            But if I use the properties set mechanism, properties are available in a snippet via the $scriptProperties array. But in this case, does it possible to retrieve (programmatically) the "default" properties before they are overriden by an another property set or snippet call ? embarrassed

            A MODx Resource should be provided that acts as the AJAX Resource.
            Have you any idea when this resource could be available ?
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              I think that means a MODx resource (document) with a blank template that holds nothing more than the snippet tags for the snippet that has the code for the AJAX processor.
                Studying MODX in the desert - http://sottwell.com
                Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                Join the Slack Community - http://modx.org
                • 5811
                • 1,717 Posts
                Thanks Susan. I understand my undertsanding problems (should be provided / will be provided ... tongue )
                In fact, I thought that a specific resource will be provided for this. Something like the index-ajax.php file for Evo.

                In the end, I will not probably use the properties mechanism, if I couldn’t retrieve the default properties from the $scriptProperties array.
                The "old" configuration file seems more efficient in my case.

                  • 28215
                  • 4,149 Posts
                  Quote from: coroico at Apr 22, 2010, 02:49 PM

                  In the end, I will not probably use the properties mechanism, if I couldn’t retrieve the default properties from the $scriptProperties array.
                  The "old" configuration file seems more efficient in my case.

                  What, wait, no - if you want the properties to be the same in the ajax handler, you should submit them via ajax to the handler from the calling page. Otherwise people cannot dynamically customize those properties.
                    shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
                    • 5811
                    • 1,717 Posts
                    What, wait, no - if you want the properties to be the same in the ajax handler, you should submit them via ajax to the handler from the calling page. Otherwise people cannot dynamically customize those properties
                    Ok, I will try to explain the things better ...

                    In the main AjaxSearch snippet, you have a default configuration file (equivalent to the locked default properties set), you could have an additional configuration file (equivalent to a custom property set) and finally some properties initialised thru the snippet call. Until here, all is simple wink
                    But for the popup window launched thru an ajax request, you should transmit the user parameters (example &opacity=`0.5` or &parents=`128`). As AjaxSearch as lot of parameters, it is better to send only the "non default" parameters thru ajax. Not all. Like in this example:
                    <script type="text/javascript">
                    //<![CDATA[
                    asvar[asvar.length]='{"vsn":"1.9.0","adv":"oneword","sub":"","bxt":"Search here...","cfg":"&asId=`as2` &category=`articleCategory` &parents=`24` &moreResultsPage=`203` "}';
                    //]]>
                    </script>
                    So, to send a limited number of parameters, I need to distinguish in the main snippet what are the default parameters (that will be retrieve in the second snippet (locked default properties set)) and what are the custom properties specifically added for an ajaxSearch on a page. This allow to have a unique hidden page with the second AjaxSearch snippet call for all the main ajaxSearch snippet calls. Whatever the custom properties added.

                    But I understand that the $scriptProperties array contains all the properties, without the possibility to distinguish the origin. So, I can’t know which properties should be send thru javascript.
                      • 22303 MODX Staff
                      • 10,725 Posts
                      Site-wide (or user or context) configuration should be done through settings that can be accessed by all parts of a multi-component piece like Search should be.