We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36786 ☆ A M B ☆
    • 209 Posts
    I am using nested getResources calls to allows for easy creation of bootstrap rows and content blocks. However, I can not seem to get it to work and always get an array. Can anyone tell me what I am doing wrong?

    My workflow is as such:
    Homepage Template -> Chunk bootstrapBlock -> Chunk oneBootstrapColumn -> Template-Dependent Formatting Chunk

    Homepage:
    [[getResources?
    	&parents=`[[*id]]`
    	&limit=`20`
    	&depth=`0`
    	&includeTVs=`1`
    	&processTVs=`1`
    	&showHidden=`1`
        &tpl=`bootstrapBlock`
    ]]


    Chunk bootstrapBlock:
    [[getResources?
    	&parents=`[[+id]]`
    	&limit=`4`
    	&depth=`0`
    	&showHidden=`1`
    	&includeTVs=`1`
    	&processTVs=`1`
        &tpl=`[[+total:is=`1`:then=`oneBootstrapColumn`:else=``]][[+total:is=`3`:then=`twoBootstrapColumn`:else=``]][[+total:is=`4`:then=`threeBootstrapColumn`:else=``]][[+total:is=`5`:then=`fourBootstrapColumn`:else=``]]`
    ]]


    Chunk oneBootstrapColumn:
    [[getResources?
    	&parents=`[[+id]]`
    	&limit=`1`
    	&depth=`0`
    	&includeTVs=`1`
    	&processTVs=`1`
    	&includeContent=`1`
    	&showHidden=`1`
        &tplCondition=`template`
    	&conditionalTpls=`{
    		"15":"staticContentBlock",
    		"16":"contactBlock",
    		"17":"pricingBlock",
    		"18":"testimonialBlock",
    		"19":"accordionBlock"
    	}`
    ]]


    Chunk staticContentBlock:
    [[*content]]


    Array Output:

    Array
    (
        [tpl] => oneBootstrapColumn
        [tplOdd] => 
        [tplFirst] => 
        [tplLast] => 
        [tplWrapper] => 
        [wrapIfEmpty] => 
        [sortby] => publishedon
        [sortbyTV] => 
        [sortbyTVType] => string
        [sortbyAlias] => 
        [sortbyEscaped] => 0
        [sortdir] => DESC
        [sortdirTV] => DESC
        [limit] => 4
        [offset] => 0
        [tvFilters] => 
        [tvFiltersAndDelimiter] => ,
        [tvFiltersOrDelimiter] => ||
        [depth] => 0
        [parents] => 14
        [includeContent] => 
        [includeTVs] => 1
        [includeTVList] => 
        [showHidden] => 1
        [showUnpublished] => 
        [showDeleted] => 
        [resources] => 
        [processTVs] => 1
        [processTVList] => 
        [prepareTVs] => 1
        [prepareTVList] => 
        [tvPrefix] => tv.
        [idx] => 1
        [first] => 1
        [last] => 1
        [toPlaceholder] => 
        [toSeparatePlaceholders] => 
        [debug] => 
        [where] => 
        [dbCacheFlag] => 0
        [context] => 
        [tplCondition] => 
        [tplOperator] => ==
        [conditionalTpls] => 
        [odd] => 1
        [id] => 15
        [type] => document
        [contentType] => text/html
        [pagetitle] => Testimonial Block
        [longtitle] => 
        [description] => 
        [alias] => testimonial-block
        [link_attributes] => 
        [published] => 1
        [pub_date] => 0
        [unpub_date] => 0
        [parent] => 14
        [isfolder] => 
        [introtext] => 
        [richtext] => 1
        [template] => 15
        [menuindex] => 0
        [searchable] => 
        [cacheable] => 1
        [createdby] => 1
        [createdon] => 2013-12-27 00:47:17
        [editedby] => 1
        [editedon] => 2013-12-27 01:52:56
        [deleted] => 
        [deletedon] => 0
        [deletedby] => 0
        [publishedon] => 2013-12-27 00:47:00
        [publishedby] => 1
        [menutitle] => 
        [donthit] => 
        [privateweb] => 
        [privatemgr] => 
        [content_dispo] => 0
        [hidemenu] => 
        [class_key] => modDocument
        [context_key] => web
        [content_type] => 1
        [uri] => new-site/homepage/block-1/testimonial-block.html
        [uri_override] => 0
        [hide_children_in_tree] => 0
        [show_in_tree] => 1
        [properties] => 
    )
    
      Ben Morrison
      Hacking templates to pieces since 2003
      • 4172
      • 5,888 Posts
      I think, what you are trying will not work.

      you can try something like that:

      [[getSubResources?
          &parents=`[[+id]]`
          &limit=`4`
          &depth=`0`
          &showHidden=`1`
          &includeTVs=`1`
          &processTVs=`1`
      ]]
      


      snippet 'getSubResources':
      <?php
      
      $totalVar = $modx->getOption('totalVar',$scriptProperties,'subTotal');
      
      $results = $modx->runSnippet('getResources',$scriptProperties);
      $total = $modx->getPlaceholder($totalVar);
      
      $tpls = array();
      $tpls[1] = 'oneBootstrapColumn';
      $tpls[3] = 'twoBootstrapColumn';
      $tpls[4] = 'threeBootstrapColumn';
      $tpls[5] = 'fourBootstrapColumn';
      
      
      $scriptProperties['tpl'] = $tpls[$total];
      return $modx->runSnippet('getResources',$scriptProperties);
      
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 36786 ☆ A M B ☆
        • 209 Posts
        I created the snippet and replaced the getResources call in the chunk "bootstrapBlock" with the getSubResources call and I still get an array.

        Array
        (
            [tpl] => 
            [tplOdd] => 
            [tplFirst] => 
            [tplLast] => 
            [tplWrapper] => 
            [wrapIfEmpty] => 
            [sortby] => publishedon
            [sortbyTV] => 
            [sortbyTVType] => string
            [sortbyAlias] => 
            [sortbyEscaped] => 0
            [sortdir] => DESC
            [sortdirTV] => DESC
            [limit] => 4
            [offset] => 0
            [tvFilters] => 
            [tvFiltersAndDelimiter] => ,
            [tvFiltersOrDelimiter] => ||
            [depth] => 0
            [parents] => 14
            [includeContent] => 
            [includeTVs] => 1
            [includeTVList] => 
            [showHidden] => 1
            [showUnpublished] => 
            [showDeleted] => 
            [resources] => 
            [processTVs] => 1
            [processTVList] => 
            [prepareTVs] => 1
            [prepareTVList] => 
            [tvPrefix] => tv.
            [idx] => 1
            [first] => 1
            [last] => 1
            [toPlaceholder] => 
            [toSeparatePlaceholders] => 
            [debug] => 
            [where] => 
            [dbCacheFlag] => 0
            [context] => 
            [tplCondition] => 
            [tplOperator] => ==
            [conditionalTpls] => 
            [odd] => 1
            [id] => 15
            [type] => document
            [contentType] => text/html
            [pagetitle] => Static Content Block
            [longtitle] => 
            [description] => 
            [alias] => static-content-block
            [link_attributes] => 
            [published] => 1
            [pub_date] => 0
            [unpub_date] => 0
            [parent] => 14
            [isfolder] => 
            [introtext] => 
            [richtext] => 1
            [template] => 15
            [menuindex] => 0
            [searchable] => 
            [cacheable] => 1
            [createdby] => 1
            [createdon] => 2013-12-27 00:47:17
            [editedby] => 1
            [editedon] => 2013-12-27 15:38:14
            [deleted] => 
            [deletedon] => 0
            [deletedby] => 0
            [publishedon] => 2013-12-27 00:47:00
            [publishedby] => 1
            [menutitle] => 
            [donthit] => 
            [privateweb] => 
            [privatemgr] => 
            [content_dispo] => 0
            [hidemenu] => 
            [class_key] => modDocument
            [context_key] => web
            [content_type] => 1
            [uri] => new-site/homepage/block-1/static-content-block.html
            [uri_override] => 0
            [hide_children_in_tree] => 0
            [show_in_tree] => 1
            [properties] => 
        )
        
          Ben Morrison
          Hacking templates to pieces since 2003
          • 22303 MODX Staff
          • 10,725 Posts
          Your $total is not going to be set until after getResources is executed, so that will not work.
            • 36786 ☆ A M B ☆
            • 209 Posts
            Ok so I found a partial solution here: https://forums.modx.com/thread/43563/solved-getresources-and-counting-children

            I installed setPaceholders and modified the getChildCount snippet to the following:

            <?php
            $count = 0;
            $parent = isset($parent) ? (integer) $parent : 0;
            if ($parent > 0) {
                $criteria = array(
                    'parent' => $parent,
                    'deleted' => false,
                    'published' => true,
                );
                $count = $modx->getCount('modResource', $criteria);
            }
            
            $modx->setPlaceholder('childCount',$count);
            
            /* return (string) $count; */


            also tried:

            $modx->setPlaceholder('childCount',(string) $count);


            and the getResources call to the following. getChildCount does output the count to the placeholder but output modifiers cause it to return blank (tested without them, the snippet works). I also tried modifying the last line of the getChildCount snippet case it needed to be output as a string. But no luck, so I had to use the "If" snippet:

            [[getChildCount? &parent=`[[+id]]`]]
            
            [[getResources?
            	&parents=`[[+id]]`
            	&limit=`4`
            	&depth=`0`
            	&showHidden=`1`
            	&includeTVs=`1`
            	&processTVs=`1`
                &tpl=`[[!If?
            		&subject=`[[+childCount]]`
            		&operator=`EQ`
            		&operand=`1`
            		&then=`oneBootstrapColumn`
            		&else=``
            ]][[!If?
               		&subject=`[[+childCount]]`
               		&operator=`EQ`
               		&operand=`2`
               		&then=`twoBootstrapColumn`
               		&else=``
            ]][[!If?
               		&subject=`[[+childCount]]`
               		&operator=`EQ`
               		&operand=`2`
               		&then=`threeBootstrapColumn`
               		&else=``
            ]][[!If?
               		&subject=`[[+childCount]]`
               		&operator=`GTE`
               		&operand=`4`
               		&then=`fourBootstrapColumn`
               		&else=``
            ]]`
            ]]
            


            It worked! "oneBootstrapColumn" was set as the tpl Parameter BUT I still get the array even though the array output the following:
            [tpl] => oneBootstrapColumn
              Ben Morrison
              Hacking templates to pieces since 2003
              • 22303 MODX Staff
              • 10,725 Posts
              I think you are delaying the logic until it is too late by using the ! on your If calls.

              Regardless, it seems to me that if you used the original getChildCount snippet which returns a value and named the chunks bootstrapColumn1, bootstrapColumn2, etc. this would be much easier...
              [[getResources?
                  &parents=`[[+id]]`
                  &limit=`4`
                  &depth=`0`
                  &showHidden=`1`
                  &includeTVs=`1`
                  &processTVs=`1`
                  &tpl=`bootstrapColumn[[getChildCount? &parent=`[[+id]]`]]`
              ]]
                • 36786 ☆ A M B ☆
                • 209 Posts
                Quote from: opengeek at Dec 27, 2013, 08:59 PM
                I think you are delaying the logic until it is too late by using the ! on your If calls.

                Regardless, it seems to me that if you used the original getChildCount snippet which returns a value and named the chunks bootstrapColumn1, bootstrapColumn2, etc. this would be much easier...
                [[getResources?
                    &parents=`[[+id]]`
                    &limit=`4`
                    &depth=`0`
                    &showHidden=`1`
                    &includeTVs=`1`
                    &processTVs=`1`
                    &tpl=`bootstrapColumn[[getChildCount? &parent=`[[+id]]`]]`
                ]]

                I reverted the getChildCount snippet to the original, changed by chunk names from "oneBootstrapColumn" to just "1" (no need for modifiers, why not cut out a step) and used your version of the chunk. STILL I get the array:

                Array
                (
                    [tpl] => 1
                    [tplOdd] => 
                    [tplFirst] => 
                    [tplLast] => 
                    [tplWrapper] => 
                    [wrapIfEmpty] => 
                    [sortby] => publishedon
                    [sortbyTV] => 
                    [sortbyTVType] => string
                    [sortbyAlias] => 
                    [sortbyEscaped] => 0
                    [sortdir] => DESC
                    [sortdirTV] => DESC
                    [limit] => 4
                    [offset] => 0
                    [tvFilters] => 
                    [tvFiltersAndDelimiter] => ,
                    [tvFiltersOrDelimiter] => ||
                    [depth] => 0
                    [parents] => 14
                    [includeContent] => 
                    [includeTVs] => 1
                    [includeTVList] => 
                    [showHidden] => 1
                    [showUnpublished] => 
                    [showDeleted] => 
                    [resources] => 
                    [processTVs] => 1
                    [processTVList] => 
                    [prepareTVs] => 1
                    [prepareTVList] => 
                    [tvPrefix] => tv.
                    [idx] => 1
                    [first] => 1
                    [last] => 1
                    [toPlaceholder] => 
                    [toSeparatePlaceholders] => 
                    [debug] => 
                    [where] => 
                    [dbCacheFlag] => 0
                    [context] => 
                    [tplCondition] => 
                    [tplOperator] => ==
                    [conditionalTpls] => 
                    [odd] => 1
                    [id] => 15
                    [type] => document
                    [contentType] => text/html
                    [pagetitle] => Static Content Block
                    [longtitle] => 
                    [description] => 
                    [alias] => static-content-block
                    [link_attributes] => 
                    [published] => 1
                    [pub_date] => 0
                    [unpub_date] => 0
                    [parent] => 14
                    [isfolder] => 
                    [introtext] => 
                    [richtext] => 1
                    [template] => 15
                    [menuindex] => 0
                    [searchable] => 
                    [cacheable] => 1
                    [createdby] => 1
                    [createdon] => 2013-12-27 00:47:17
                    [editedby] => 1
                    [editedon] => 2013-12-27 15:38:14
                    [deleted] => 
                    [deletedon] => 0
                    [deletedby] => 0
                    [publishedon] => 2013-12-27 00:47:00
                    [publishedby] => 1
                    [menutitle] => 
                    [donthit] => 
                    [privateweb] => 
                    [privatemgr] => 
                    [content_dispo] => 0
                    [hidemenu] => 
                    [class_key] => modDocument
                    [context_key] => web
                    [content_type] => 1
                    [uri] => new-site/homepage/block-1/static-content-block.html
                    [uri_override] => 0
                    [hide_children_in_tree] => 0
                    [show_in_tree] => 1
                    [properties] => 
                )
                
                  Ben Morrison
                  Hacking templates to pieces since 2003
                  • 22303 MODX Staff
                  • 10,725 Posts
                  Still sounds like it's not able to find the tpl for some reason, but I cannot see an obvious reason why from what you've posted...
                    • 36786 ☆ A M B ☆
                    • 209 Posts
                    Oi vey, never a good thing. Maybe I should give up the ghost in counting children and have multiple templates/containers for different quantities of content blocks. Conditional Tpls based on quantity of children would be a great addition to getResources, especially for bootstrap fanatics like me. Anyone know where I could suggest such a feature? As it is tplCondition isn't properly documented.
                      Ben Morrison
                      Hacking templates to pieces since 2003
                      • 22303 MODX Staff
                      • 10,725 Posts
                      I think something simple is missing in your approach, but without seeing exactly how it is being used, it's hard for me to pinpoint what that might be. Could it be this? Have you put anything in those Chunks.

                      As for feature suggestions, you can make those at https://github.com/opengeek/getresources/issues