We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 12893
    • 13 Posts
    Is there any way to retrieve resources based on parent ID, but to use a different template for each parent? The only way I found to do this was to split my getResources call into a separate call for each parent, but this is not a very good solution as I can’t reorder the resources. I’ve tried using "&tpl_n" but that doesn’t seem to have anything to do with the parent ID. Below is an example of the 3 calls which I would like to combine into 1. Any help would be greatly appreciated. Thanks!

    [[!getResources?
       &parents=`1`
       &tpl=`template1`
    ]]
    [[!getResources?
       &parents=`2`
       &tpl=`template2`
    ]]
    [[!getResources?
       &parents=`3`
       &tpl=`template3`
    ]]
    
      • 15162
      • 59 Posts
      I have the same problem, I think. I want to call documents with one getResources call, but have each of them use a different template based on their parent. It’s not ideal for me to use only one template as the documents that get retrieved don’t all share the same fields or TVs.

      The only solution I have found is to use the IF snippet or output filters. I’m using IF. So at this moment I have a template for my getResources call that has four IF calls in it. This makes my page load very slowly and I’m looking for a better way of achieving "our" goal. Just to give a picture: the page that uses the IF calls is about the same size as another page I have, that doesn’t use any IF calls. The page without the IF calls loads at least four times faster! When using Firebug to diagnose, both of the pages’ first GET are around 7kb in size. Page with IF calls loads it in 4,5 seconds (hrrrr....) and the page without it in less than one second. Not all of the difference is due to the IF calls, but a great deal of it. Removing the IF calls results in a load time under 2 seconds.

      But for your consideration I’m going to leave the awful method here. I’m hoping that someone else could enlighten us with more optimized solution smiley

      Call:
      [[!getResources? 
         &parents=`1,2,3,4`
         &limit=`10`
      
         &showHidden=`1` 
         &includeTVs=`1`
         &processTVs=`1`
         &includeContent=`1`
      
         &tpl=`exampleTpl`]]


      exampleTpl:
      [[!If? &subject=`[[+parent]]` &operand=`1` &then=`contents of first tpl`]]
      [[!If? &subject=`[[+parent]]` &operand=`2` &then=`contents of second tpl`]]
      
      ...
        • 20471
        • 40 Posts
        Oh I so need this too! Got 2 parents (Portfolio and Journal) and want to list the children these in reversed date order on the start page, obviously with different templates.
          • 15162
          • 59 Posts
          I’ve looked into this for a while now and found no solution. I guess the "right" way would be writing a completely new snippet? I’m going to look into it a bit more, but my PHP experience is zero... So it might take a while before I have anything to offer laugh