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

    I would like to make nested getResources calls. I have made folders (which act as FAQ categories) with resources in them (which act as the actual questions). So my desirable output will look like this:

    General questions
    - General question 1
    - General question 2


    Technical questions
    - Technical question 1
    - Technical question 2


    And so on..

    You can make this with nested ditto calls, as described here: http://modxcms.com/forums/index.php/topic,49841.0.html. But I would like to do it with getResources, because I like getResources smiley. My approach is as follows:

    Chunk [[!$faq]] (so my end-users can’t scew up the getResources call)
    [[getResources? &parents=`40` &tpl=`faqCategories` &depth=`1` &includeContent=`1`]]


    Chunk tpl faqCategories
    <h3>[[+pagetitle]]</h3>
    [[!getResources? &parents=`[[+id]]` &tpl=`faqCategoriesChild` &depth=`1` &includeContent=`1`]]
    <hr />
    


    Chunk tpl faqCategoriesChild
    <h4>[[+pagetitle]]</h4>
    <p>[[+content]]</p>


    This outputs only the following by me:

    - Financial question 1
    - Technical question 1
    - Technical question 2


    Financial questions
    - Financial question 1
    - Financial question 2


    General questions
    - General question 1
    - General question 2


    (Bold = <h3>)
    (Italic = <h4>)

    Look what happens with the financial question 1! It’s printed twice. Once as a <h3> (should be only used for category heading), and once as a <h4>, nicely inside it’s category. Some other questions also don’t turn out well, and some others do turn out well as you can see. I’ve no idea what caused this. I’ve double checked all resources for ’is folder’, ’published’, and so on..

    Well.. actually my question is as follows; can I use nested getResources calls?

    (I’m using modx 2.0.4-pl2 with getResources 1.2.2pl)


    (tags: call inside call, sort, show child sorted by parent)
      • 15022
      • 31 Posts
      Hello,

      Simple answer is: Yes you can nest getResources calls.

      You might try
      in your chunk, call getResources uncached
      [[!getResources? &parents=`40` &tpl=`faqCategories` &depth=`1` &includeContent=`1`]]


      and try adding:
      &hideContainers=`1`
      &limit=`0` (in case you have more than 5)


      A side note: I like to use definition list markup for FAQs (<dl> <dt> <dd>)

      faqCategories

      <h3>[[+pagetitle]]</h3>
      <dl>
      [[!getResources? &parents=`[[+id]]` &tpl=`faqCategoriesChild` &depth=`1` &includeContent=`1` &hideContainers=`1` &limit=`0`]]
      </dl>


      faqCategoriesChild

      <dt>[[+pagetitle]]</dt>
      <dd>[[+content]]</dd>


      If those changes don’t work, could you provide info about how your resources are organized in the resource "tree"?
        illegitimati non carborundum
        • 3749
        • 24,544 Posts
        You might want to take a look at the EZfaq snippet for a quick, easily managed FAQ. It won’t give you the flexibility of getResources, but it will use a lot less memory and storage space since all the questions and answers are in a single chunk rather than being split among many resources. That might also make it easier to maintain. You can have as many FAQs as you need with it.

        If that won’t meet your needs (it sounds like you may need questions to be in multiple categories) you might consider putting the questions and answers in a custom DB table and using a custom snippet with xPDO to pull the ones you need. That would be infinitely more efficient, but a lot more work to set up.
          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