We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 22244
    • 144 Posts
    Dear MODx community,

    I have been wondering for 3 hours why oh why my Doodles snippet code that I have saved under Snippets in the Manager won’t take a custom chunk.

    This is the default Doodles snippet code that sets the chunk:
    /* setup default properties */
    $tpl = $modx->getOption(’tpl’,$scriptProperties,’rowTpl’);

    Now I want to set another chunkname, I tried:
    /* setup default properties */
    $tpl = $modx->getOption('tpl',$scriptProperties,'myRowTpl'); - no effect, it defaults back to the rowTpl (why???)
    


    Looking at another module where they used:
    /* setup default properties */
    $tpl = $modx->getOption('myTpl',$scriptProperties,false); - also no effect, it defaults back to the rowTpl (why???)
    


    I kinda worked around it by giving my chunk name later in at the iterate point in the snippet but I still want to know what goes wrong where and why.

    /* iterate */
    $output = '';
    foreach ($brands as $brand) {
        $output .= $bcon->getChunk(myTpl,$brand->toArray());
    }
    



    I’m so stuck on this and some help would be so appreciated!
      • 22244
      • 144 Posts
      I now have:
      $mytpl = $modx->getOption('mytpl',$scriptProperties,'customTpl');
      


      $output .= $bcon->getChunk($mytpl,$brand->toArray());


      But how can it be the other examples in my post above always default to rowTpl??? Even when the name is not rowTpl.

      Is this a MODx setting / default that I should be aware of?
        • 28215
        • 4,149 Posts
        Do the Snippets in the mgr have ’default properties’ that would be overriding that code?
          shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
          • 22244
          • 144 Posts
          <?php
          /**
           * @package bcontrol
           */
          $bcon = $modx->getService('bcontrol','Bcontrol',$modx->getOption('bcontrol.core_path',null,$modx->getOption('core_path').'components/bcontrol/').'model/bcontrol/',$scriptProperties);
          if (!($bcon instanceof Bcontrol)) return '';
          
          /* setup default properties */
          $mytpl = $modx->getOption('tpl',$scriptProperties,'brandsTpl');
          $sort = $modx->getOption('sort',$scriptProperties,'brandid');
          $sort = $modx->getOption('sort',$scriptProperties,'name');
          $dir = $modx->getOption('dir',$scriptProperties,'ASC');
          
          /* build query */
          $c = $modx->newQuery('Brand');
          $c->sortby($sort,$dir);
          $brands = $modx->getCollection('Brand',$c);
          
          /* iterate */
          $output = '';
          foreach ($brands as $brand) {
              $output .= $bcon->getChunk($mytpl,$brand->toArray());
          }
          
          return $output;


          The above defaults to chunk rowTpl. I thought by setting $mytpl = $modx->getOption(’tpl’,$scriptProperties,’brandsTpl’); I can set my template to be brandsTpl but this code defaults to rowTpl. I have no snippet uploaded to the filesystem or anything else. This is an ajusted version of the Doodles module.

          But $mytpl = $modx->getOption(’mytpl’,$scriptProperties,’brandsTpl’); uses the brandsTpl.

          I’m still wondering where the code "gets to understand to go and get rowTpl.

          Thanks for helping me understand!
            • 28215
            • 4,149 Posts
            In the Snippet you put inside the MODX manager, are there any properties set on it.
              shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
              • 22244
              • 144 Posts
              Wow Splittingred, that’s it!

              This makes things clear.
              I only had no clue these properties were loaded there. Were they set with the first save of the snippet?

              Thanks for the help!!!
                • 22244
                • 144 Posts
                Can it be these property settings are set when you install a module via a transport package?
                Is there an other way they are automatically set in a snippet?
                  • 28215
                  • 4,149 Posts
                  No; they are set via the build script when you install most packages.

                  If you’re developing, it’s recommended to just delete them, as they are fed into the $scriptProperties array.
                    shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com