We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 46396
    • 14 Posts
    hello
    in my website I have three children pages for each child page I created a TV that contains a list of keywords. in the parent page I want to display a paragraph of all three lists into a single list.
    how can I do ?
    thank you very much for your help
      • 42562
      • 1,145 Posts
      The question is not clear...
      Break the sentence down a bit.

      One parent page
       |
        ---Three children pages (ids=12, 24, 34)
           |
           ---Each has a TV with list of keywords


      in the parent page I want to display a paragraph of all three lists into a single list.?

      You can use http://rtfm.modx.com/extras/revo/getresourcefield
      in your parent page
      [[getResourceField? &id=`12` &field=`myTV` &processTV=`1` ]]
      [[getResourceField? &id=`24` &field=`myTV` &processTV=`1` ]]
      [[getResourceField? &id=`34` &field=`myTV` &processTV=`1` ]]


      There is a better way, and faster I think, using the MODx api. One call instead of three.
        TinymceWrapper: Complete back/frontend content solution.
        Harden your MODX site by passwording your three main folders: core, manager, connectors and renaming your assets (thank me later!)
        5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.
        • 3749
        • 24,544 Posts
        donshakespeare's method looks fine, but I think this will do it with one query and no extra function calls (untested):


        <p>[[!KeyWordList]]</p>

        <?php
        /* KeyWordList snippet */
        $docId = $modx->resource->get('id');
        $tvId = 12;  /* set to the ID of your TV */
        $childIds = $modx->getChildIds($docId);
        $c = $modx->newQuery('modTemplateVarResource');
        
        $c->where(array(
          'tmplvarid' => $tvId,
          'contentid:IN' => $childIds,
        ));
        
        $tvts = $modx->getCollection('modTemplateVarResource', $c);
        
        $list = '';
        $prefix = '';
        foreach ($tvts as $tvt) {
          $list .= $prefix . $tvt->get('value');
          $prefix = ',';
        }
        
        return $list;
        


        This assumes that you can use the raw output of the TVs, which is significantly faster. That should be fine since they're just text.
        [ed. note: BobRay last edited this post 12 years, 7 months ago.]
          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
          • 4172
          • 5,888 Posts
          I think, it will work a bit better, if getCollection uses the same classname as newQuery

          <?php
          
          /* KeyWordList snippet */
          $docId = $modx->resource->get('id');
          $tvId = 12; // set to the ID of your TV 
          $childIds = $modx->getChildIds($docId);
          $classname = 'modTemplateVarResource';
          $c = $modx->newQuery($classname);
          
          $c->where(array(
              'tmplvarid' => $tvId,
              'contentid:IN' => $childIds,
              ));
          
          $list = '';
          if ($tvts = $modx->getCollection($classname, $c)) {
              $prefix = '';
              foreach ($tvts as $tvt) {
                  $list .= $prefix . $tvt->get('value');
                  $prefix = ',';
              }
          }
          
          return $list;
          
          [ed. note: Bruno17 last edited this post 12 years, 7 months ago.]
            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 3749
            • 24,544 Posts
            wink I blame my medication wink
              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
              • 46396
              • 14 Posts
              Quote from: BobRay at Mar 01, 2014, 01:15 AM
              donshakespeare's method looks fine, but I think this will do it with one query and no extra function calls (untested):


              <p>[[!KeyWordList]]</p>

              <!--?php
              /* KeyWordList snippet */
              $docId = $modx--->resource->get('id');
              $tvId = 12;  /* set to the ID of your TV */
              $childIds = $modx->getChildIds($docId);
              $c = $modx->newQuery('modTemplateVarResource');
              
              $c->where(array(
                'tmplvarid' => $tvId,
                'contentid:IN' => $childIds,
              ));
              
              $tvts = $modx->getCollection('modTemplateVarResource', $c);
              
              $list = '';
              $prefix = '';
              foreach ($tvts as $tvt) {
                $list .= $prefix . $tvt->get('value');
                $prefix = ',';
              }
              
              return $list;
              


              This assumes that you can use the raw output of the TVs, which is significantly faster. That should be fine since they're just text.

              Hello,
              First thank you for your help, the BobRay (and Bruno17) snippet it works.

              Now I also want to display three <ul> in the parent page. <ul> is a reference of a child page.

              each <ul> has a keywords list as class and it must be a wrap of all the keywords as a link.

              For example, for first child page I want to display:
              <ul class ="keywords list for first child page">
              <a href=" "> keyword 1 </a>
              <a href = ""> Keyword 2 </a>
              ...
              </ul>
              I hope it is clear
              I'm already trying with placehoder and str_remplace, but Ican not make it work well, I suppose I missed something in my modest snippet. Thank you again for your help.
                • 3749
                • 24,544 Posts
                To do it all in the snippet:

                <?php
                 
                /* KeyWordList snippet */
                $docId = $modx->resource->get('id');
                $tvId = 12; // set to the ID of your TV 
                $childIds = $modx->getChildIds($docId);
                $classname = 'modTemplateVarResource';
                $c = $modx->newQuery($classname);
                 
                $c->where(array(
                    'tmplvarid' => $tvId,
                    'contentid:IN' => $childIds,
                    ));
                 
                
                $output = '';
                if ($tvts = $modx->getCollection($classname, $c)) {
                    $list = '';
                    foreach ($tvts as $tvt) {
                        $list = $tvt->get('value');
                        $output .= "\n<ul>";
                        $terms = explode(',', $list);
                        foreach ($terms as $term) {
                            $output .= "\n    <li>" . trim($term) . '</li>';
                        }
                        $output .= "\n</ul>";
                    }
                }
                 
                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