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

    I’m new in modx and I have a little problem :
    I call with the getresources snippet some documents that contain a TV called "article_type".
    I would like to output this document in different template depending this TV.
    So in my model :
    <div id="right_column">
    [[!getResources? &parents=`7` &includeTVs=`1` &showHidden=`1` &processTVs=`1` &tpl=`[[*article_type]]` &includeContent=`1`]]
    </div>

    But this is not the tv of the resource that is interpreted.

    How can I do ?

    Thanks
      • 32098
      • 31 Posts
      Fepia,

      Sorry can’t give you a complete solution because I too am struggling to keep my head above the choppy waters of Modx, and it sounds as if you need a conditional statement somewhere to pick out the appropriate template if... and that is beyond me at this point in my (R)evolution.

      However, let me suggest that your &tpl= bit is not quite right. From what I gather, at this point getResources looks for a template with the given name in the chunks section of Modx. So you create your little template, save it as a chunk and then put the name of that chunk (without brackets, dollar signs, exclamation marks or other embellishments) between the backticks of the &tpl=

      To pull in the stuff from the appropriate TV just make sure (although you probably already know this) that the chunk includes the right kind of ref to the TV, like so:

      <div>[[+tv.mytvname]]</div>


      Be aware of getResources looking by default for TVs prefixed with tv.

      Took me the best part of a day to avoid that pitfall.

      Good luck
        • 3749
        • 24,544 Posts
        If I’m understanding you, I think you’d need a custom snippet rather than getResources.

        You’d use modx->getCollection() to get the resources, test the TV value, then use $modx->getChunk() to get the appropriate Tpl chunk and add the result to the $output variable.

        Something like this (untested):

        <?php
        
        /* parentId would be a parameter in the snippet tag */
        $resources = $modx->getCollection('modResource', array('parent'=>$parentId, 'published'=>'1', 'deleted'=>`0`));
        
        $foreach ($resources as $resource) {
        
          $id = $resource->get('id');
        
          $tvValue = $resource->getTVValue('articleType');
        
          $output .= $modx->getChunk('$tvValue', $resource->toArray() );
        
          /* You'd have to get any other TV's to display and set placeholders for their values here */
        }
        
        return $output;
        

          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