We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 49659
    • 86 Posts
    OK, I was able to find two cascading points of failure. I got the first failure point to work with the switched template, but I'm stuck on the second.

    For your reference, here's the last part of the customized 'GetUsers' snippet, showing the failure points:
    [snip]...
    /** START FIRST failure point */
        //$inner = $modx->getChunk($innerTpl, $fields);
    /** END FIRST failure point */        
    /** START added by Karl */    
        $inner = '[[+extUserRow]]';
    /** END added by Karl */
    
        $row = $modx->getChunk($rowTpl, $fields);
        
        $innerOutput .= str_replace('[[+extUserRow]]', $row, $inner);
        $i++;
    }
    
    /** START added by Karl */    
        $modx->log(modX::LOG_LEVEL_ERROR, '[GetExtUsersCustom] innerOutput = ' . $innerOutput);
    /** END added by Karl */
    
    /** START SECOND failure point */
    $output = str_replace('[[+extUserInner]]', $innerOutput, $outer);
    /** END SECOND failure point */
    
    /** START added by Karl */    
        $modx->log(modX::LOG_LEVEL_ERROR, '[GetExtUsersCustom] output = ' . $output);
    /** END added by Karl */
    
    return $output;


    Re: First failure point (fixed) - When viewing the page with the switched template, this line:
    $inner = $modx->getChunk($innerTpl, $fields);

    ..was failing to get the value in the $innerTpl chunk, which meant that the $inner and the $innerOutput variables were not getting set.

    Because the only value in the $innerTpl chunk is '[[+extUserRow]]', I reduced the overhead of setting the $inner variable by setting it directly (see code above). Now, the $innerOutput variable populates when viewing the page with the switched template.

    Re: Second failure point - When viewing the page with the switched template, this line:
    $output = str_replace('[[+extUserInner]]', $innerOutput, $outer);

    ..fails to integrate the $innerOutput chunk value with the $outer variable, leaving the switched template page with only the header, and missing the body of the user list.

    I don't know what can be done, if anything, to fix the second failure point, which comes at the very end of the snippet. Am grateful for your help troubleshooting this, and appreciate any ideas to get past this last obstacle.

    Best wishes,

    Karl Forsyth
      • 13428 ☆ A M B ☆
      • 1,031 Posts
      Sorry, I don't see the issue in your code that makes it impossible to work with SwitchTemplate.