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

    I'm using a customized version of the 'GetExtUsers' snippet (from Bob Ray's Class Extender) to list some users to a Resource on the front end. This works fine with the default template assigned to the Resource.

    However, I need to be able to optionally open this user list to a clean printable page, and was thinking I could use the 'SwitchTemplate' extra to accomplish this.

    I installed SwitchTemplate and created a new setting with the key 'printview'. I added this parameter to the Resource URL:
    ?mode=printview


    That parameter opens the Resource with the correct printable template, but the user data which is generated from the customized 'GetExtUsers' snippet does not appear in the template-switched page. Apparently, there's some timing conflict that causes the user data to not make it to the rendered page when a template switch occurs.

    Any ideas on how to troubleshoot this, or if there are any workarounds?

    Thanks,

    Karl Forsyth
      • 3749
      • 24,544 Posts
      Does the data show up if you do a "View Source" on the page?

      Is the getExtUsers snippet tag in the template or page content of the page?
        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
        • 49659
        • 86 Posts
        Hi Bob,

        I did a 'View Source' and the user data doesn't show up at all.

        The snippet is in the content field of the Resource, as follows:
        <div id="myList">
        [[!GetExtUsersCustom@SoCoGetExtUsersProperties?
            &sortby=`lastName`
            &sortDir=`ASC`
            &extUserOuterTpl=`ExtUserOuterTplCustom`
            &extUserInnerTpl=`ExtUserInnerTplCustom` 
            &extUserRowTpl=`ExtUserRowTplCustom`
            &where=`{"UserGroupMembers.user_group:=":"6"}`
        ]]
        </div>


        As you can see, I modified the original 'GetExtUsers' snippet to take a group argument in the &where parameter.

        Here's the 'ExtUserOuterTplCustom' chunk. The <tbody> section is empty on the rendered page:
        <h3 align="center">User Group: [[+groupName]]</h3>
        <div style="float: right; padding-right: 15px;font-style: italic;">Date printed: [[+datePrinted]]</div>
        <div style="float: left; padding-left: 15px;font-style: italic;"><a class="btn-CSS" href="[[~[[*id]]]]?mode=printview" target="new">Printable View</a></div>
        <br />
        <div class = "ext-users">
            <table>
                <thead>
                    <tr class="ext-user-row">
                        <th class="ext-user-field" width="150">User Name</th>
                        <th class="ext-user-field">Login Name</th>
                        <th class="ext-user-field" width="150">Email</th>
                        <th class="ext-user-field" width="100">Preferred Role</th>
                        <th class="ext-user-field" width="100">Last Payment Date</th>
                        <th class="ext-user-field" width="100">Membership Expiration Date</th>
                        <th class="ext-user-field">Group membership</th>
                    </tr>
                </thead>
                <tbody>
                <!-- the 'extUserInner' chunk goes here -->
                [[+extUserInner]]
                </tbody>
            </table>
        </div>
        <!-- END ext-users -->
        


        The 'ExtUserInnerTplCustom' chunk only has this value:
        [[+extUserRow]]


        The 'ExtUserRowTplCustom' has this:
            <tr class="ext-user-row">
                <td class="ext-user-field">[[+data_lastName:ne=``:then=`[[+data_lastName]], [[+data_firstName]]`:else=`[[+profile_fullname]]`]]</td>
                <td class="ext-user-field">[[+username]]</td>
                <td class="ext-user-field">[[+profile_email]]</td>
                <td class="ext-user-field">[[+data_prefRole]]</td>
                <td class="ext-user-field">[[+data_lastPymtDate:strtotime:date=`%D`]]</td>
                <td class="ext-user-field">[[+data_memberExpireDate:strtotime:date=`%D`]]</td>
                <td class="ext-user-field">
                    <ul>
                    [[PeopleGroups? &user=`[[+id]]` &limit=`0`]]
                    </ul>
                </td>
            </tr>


          • 13428 ☆ A M B ☆
          • 1,031 Posts
          What template type do you use for this? Chunk or Template?
            • 49659
            • 86 Posts
            Template
              • 49659
              • 86 Posts
              I just realized something else about this...

              I have a snippet call in the <head> which contains calls to load css and js files, and none of those get loaded when triggering SwitchTemplate.

              Here are the function calls in the snippet that load fine with the default template:
              <?php
              $modx->regClientCSS('assets/css/menucool-horiz.css');
              $modx->regClientCSS('assets/meanMenu/meanmenu.css');
              $modx->regClientCSS('assets/galleria/themes/classic/galleria.classic.min.js');
              $modx->regClientCSS('assets/css/soco-prod.css');
              $modx->regClientCSS('assets/css/soco-theme-prod.css');
              $modx->regClientCSS('http://fonts.googleapis.com/css?family=Belleza');
              $modx->regClientCSS('http://fonts.googleapis.com/css?family=Ubuntu:400,400italic,700');
              $modx->regClientStartupScript('http://code.jquery.com/jquery-latest.min.js');
              $modx->regClientStartupScript('assets/meanMenu/jquery.meanmenu.js');
              $modx->regClientStartupScript('assets/galleria/galleria-1.4.2.min.js');
              $modx->regClientStartupScript('assets/js/JSDValidator-1.6.min.js');
              $modx->regClientStartupScript('assets/js/jQuery-Form-Validator/form-validator/jquery.form-validator.js');
              $modx->regClientStartupScript('assets/js/soco-prod.js');
              $modx->regClientStartupScript('assets/js/soco-prod-validate.js');
              $modx->regClientStartupScript('assets/js/soco-theme.js');


              Karl
                • 13428 ☆ A M B ☆
                • 1,031 Posts
                regClient functions are not possible at the moment.

                I am not sure why the snippet call has issues. Maybe because of the property set. Could you first try to check it with a chunk as template for SwitchTemplate.
                  • 3749
                  • 24,544 Posts
                  I've had regClient functions fail if there's no head section at the time they execute, or if the Template's HTML is malformed. I think I've also had them fail because of a missing or incorrect DOCTYPE, but I can't remember for sure.
                    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
                    • 49659
                    • 86 Posts
                    Hi Jako,

                    I copied the content of the target template to a chunk and redefined the setting in SwitchTemplate to use that chunk.

                    There's no change in behavior. It does switch to that chunk, but it does not load the regClient functions and the 'GetExtUsersCustom' snippet call fails at the [[+extUserRow]] call.

                    Karl
                      • 13428 ☆ A M B ☆
                      • 1,031 Posts
                      @BobRay: No, thats a limitation of SwitchTemplate.