We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 34004
    • 125 Posts
    I am using getresources to build a table of data. This is my getResources call:

    [[!getResources?
    					&parents=`5`
    					&includeTVs=`1`
    					&processTVs=`1`
    					&tplPath=`[[++assets_path]]web_assets/chunks/`
    					&tpl=`@FILE table-capabilities.htm` 
    					&includeContent=`1`
    					&depth=`0`
    					&limit=`99`
    					&offset=`1`
    					&sortby=`{"menuindex":"ASC"}`
    				]]
    


    Here's what's in table-capabilities.htm (the cells with switch-table chunk in it are what I need help with):

    <tr>
    	<td>[[+pagetitle]]</td>
    	<td>[[+tv.product-code]]</td>
    	<td>[[+tv.product-quantity]]</td>
    	<td>[[$switch-table? &input=`[[+tv.product-capability-static]]`]]</td>
    	<td>[[$switch-table? &input=`[[+tv.product-capability-contrast]]`]]</td>
    </tr>
    


    and I'm using a chunk called switch-table which has this code in it:

    [[!switch? 
        &get=`[[+input]]`
        &c1=`No` &do1=`<span class="label label-important"><i class="icon-remove icon-white"></i> No</span>`
        &c2=`Yes` &do2=`<span class="label label-success"><i class="icon-ok icon-white"></i> Yes</span>`
        &c3=`Refer` &do3=`<span class="label label-info"><i class="icon-share-alt icon-white"></i> Refer</span>`
        &c4=`Alert` &do4=`<span class="label label-warning"><i class="icon-question-sign icon-white"></i> Alert!</span>`
        &default=`<span class="label"><i class="icon-exclamation-sign icon-white"></i> Default</span>`
    ]]  
    
    


    So I am trying to use getresources to draw a table using switch in a chunk to style the data in the table, by passing it the placeholder as a variable. I've tried all manner of uncached calls for chunks, placeholders and snippets to try to get this to work however it seems to be either

    Caching the first call so everything is "default"
    Only executing the first condition of the switch snippet so everything after "no" doesn't show
    Only executing the first condition on the first row of the getresources call, everything below is blank.

    Any ideas how to get this working reliably? I could probably put the switch call in the table-capabilities.htm and it will work, but that's not really how things are supposed to work in MODx no?



      • 4172
      • 5,888 Posts
      did you try to call both [[getResources and [[switch cached ?

      May be you will need to make each tag for each resource unique

      [[$switch-table? &docid=`[[+id]]` &input=`[[+tv.product-capability-static]]`]] 


      [[switch?
          &docid=`[[+docid]]`
          &get=`[[+input]]`
      

        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 34004
        • 125 Posts
        Thanks Bruno for the reply. I tried what you suggested but it didn't work.

        When I call both [[getResources and [[switch cached I only get the first getresources row returned, and only the values which are first. For example, the first record from the getresources call for this placeholder: <td>[[$switch-table? &input=`[[+tv.product-capability-static]]`]]</td> has a value of "Yes" so the switch call works for the first and subsequent "yes" for only the first getresources recored but subsequent records are blank.

        My code is now:

        [[getResources?
        					&parents=`5`
        					&includeTVs=`1`
        					&processTVs=`1`
        					&tplPath=`[[++assets_path]]web_assets/chunks/`
        					&tpl=`@FILE table-capabilities.htm` 
        					&includeContent=`1`
        					&depth=`0`
        					&limit=`999`
        					&offset=`1`
        					&sortby=`{"menuindex":"ASC"}`
        				]]


        <tr>
        	<td>[[+pagetitle]]</td>
        	<td>[[+tv.product-code]]</td>
        	<td>[[+tv.product-quantity]]</td> 
        	<td>[[$switch-table? &docid=`[[+id]]` &input=`[[+tv.product-capability-static]]`]]</td>
        	<td>[[$switch-table? &docid=`[[+id]]` &input=`[[+tv.product-capability-contrast]]`]]</td>
        
        </tr>
        
        


        [[switch? 
        	&docid=`[[+docid]]`
            &get=`[[+input]]`
            &c1=`No` &do1=`<span class="label label-important"><i class="icon-remove icon-white"></i> No</span>`
            &c2=`Yes` &do2=`<span class="label label-success"><i class="icon-ok icon-white"></i> Yes</span>`
            &c3=`Refer` &do3=`<span class="label label-info"><i class="icon-share-alt icon-white"></i> Refer</span>`
            &c4=`Alert` &do4=`<span class="label label-warning"><i class="icon-question-sign icon-white"></i> Alert!</span>`
            &default=`<span class="label"><i class="icon-exclamation-sign icon-white"></i> Default</span>`
        ]]  
        
        


        I'm about to call everything uncached and see what happens.
          • 34004
          • 125 Posts
          I've managed to show all "Yes" for each getresources record. From what I can tell the switch snippet is caching the first substitution it makes - so all "Yes" will show but everything else is blank. If I change the first "Yes" into a "No" then all the "No"s show and the "yes" are blank.

          Hard to explain so here's a screenshot attached. I think this has something to do with it (which is unsolved): http://forums.modx.com/thread/43638/getresources-is-cached-in-second-call-and-later
            • 4172
            • 5,888 Posts
            you can try the chunks uncached:

                <td>[[!$switch-table? &docid=`[[+id]]` &input=`[[+tv.product-capability-static]]`]]</td>
                <td>[[!$switch-table? &docid=`[[+id]]` &input=`[[+tv.product-capability-contrast]]`]]</td>
              -------------------------------

              you can buy me a beer, if you like MIGX

              http://webcmsolutions.de/migx.html

              Thanks!
              • 34004
              • 125 Posts
              Quote from: Bruno17 at Feb 18, 2013, 12:50 PM
              you can try the chunks uncached:

              Unfortunately this just makes everything blank. I believe the &input value is going through to the switch snippet, however switch isn't evaluating anything past the first result, so it must be cached somewhere. I've tried passing in &n=`[[+idx]]` so each call is unique, but once again everything goes blank.
                • 34004
                • 125 Posts
                Just wondering if anyone had any clues perchance? Would really like to solve this one... thanks
                  • 36996
                  • 211 Posts
                  There's no $ in your switch chunk
                    • 34004
                    • 125 Posts
                    Thanks for reply, [[Switch]] is a snippet not a chunk so I don't need a $ at the start ?
                      • 36996
                      • 211 Posts
                      Sorry I misread.
                      Did you try to replace the replace-table chunk inside the table capabilities chunk with the actual switch snippet call?