We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36830
    • 140 Posts
    used this tut (http://rtfm.modx.com/display/revolution20/Creating+a+multi-select+box+for+related+pages+in+your+template) to create a checkbox tv in a resource that should allow client to select what resources to display on the page. However, two problems... it's working but with limitations that i desperately need to resolve: 1. in TV Input Option Values, how do i get the
    @EVAL return $modx->runSnippet('getResources',array('parent' => 18));
    to output more than one parent's resources in the resource where the TV appears (need client to choose from a list of resources that have different parents)? 2. (thread topic) how do i get the snippet call:
    [[relatedPages? &input=`[[*relatedPages]]` &tpl=`relatedPagesTpl`]]
    to display the image TVs from the aggregated resources? Thanks so much for any assistance. Deadline's coming like a comet.
    • 1: This should work (though untested..!)
      @EVAL return $modx->runSnippet('getResources',array('parent:IN' => array(18,15,13)));


      2: You'll need to modify the snippet to also include TV values.

      Something like this should work when using 2.1+ to retrieve the values and make them accessible with [[+tvname]] (but again.. untested).
      if (empty($input)) { return 'This article is so unique, that we couldn\'t find anything related to it!'; }
      $tpl = $modx->getOption('tpl',$scriptProperties,'relatedPagesTpl');
      if ($modx->getChunk($tpl) == '') { return 'We found some related pages, but don\'t know how to present it.'; }
      $ids = explode(',', $input);
      $output = array();
      foreach ($ids as $key => $value) {
        $resource = $modx->getObject('modResource',array(
          'published' => 1,
          'id' => $value));
        if ($resource instanceof modResource) {
          $ta = $resource->toArray();
          $ta = array_merge($ta,$resource->getTemplateVars());
          $output[] = $modx->getChunk($tpl,$ta);
        }
      }
      return implode('',$output);
      

        Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

        Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
        • 37802
        • 11 Posts
        Thanks Mark for your suggestions, which I have tried. Unfortunately, the final output to the page doesn't show the Template Variables from the related resources sad

        I'm using Revo v2.1.3-pl.

        Any assistance would be very much appreciated.
        Thanks.
        Theo.
        • You can also give the getRelated snippet a shot, which has support for TVs now and doesn't require you to select pages manually.

          Can you show how you're calling the snippet in the template?
            Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

            Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
            • 37802
            • 11 Posts
            Good call, was considering that but wanted to remain faithful to your article smiley

            Sure, like this:
            [[relatedPages? &input=`[[*relatedPages]]` &tpl=`panelTpl`]]
              • 37802
              • 11 Posts
              Sorry, posting the code here stripped out some of it, here it is again:

              [[relatedPages? &input=`[[*relatedPages]]` &tpl=`panelTpl`]]
              • Can you show your panelTpl?

                I think we'll need to customize the snippet:

                if (empty($input)) { return 'This article is so unique, that we couldn\'t find anything related to it!'; }
                $tpl = $modx->getOption('tpl',$scriptProperties,'relatedPagesTpl');
                if ($modx->getChunk($tpl) == '') { return 'We found some related pages, but don\'t know how to present it.'; }
                $ids = explode(',', $input);
                $output = array();
                foreach ($ids as $key => $value) {
                  $resource = $modx->getObject('modResource',array(
                    'published' => 1,
                    'id' => $value));
                  if ($resource instanceof modResource) {
                    $ta = $resource->toArray();
                    $tvs = $resource->getTemplateVars();
                    foreach ($tvs as $tv) {
                       $ta[$tv->get('name')] = $tv->get('value');
                    }
                    $output[] = $modx->getChunk($tpl,$ta);
                  }
                }
                return implode('',$output);


                Untested
                  Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

                  Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
                  • 37802
                  • 11 Posts
                  Of course, here's the panelTpl:

                  <div class="wslpanel">
                  <div class="wslpaneltitle"><h3>[[+TV Panel Title]]</h3></div>
                  <div class="wslpanelimage" style="background-image:url(assets/templates/wos/panels/[[+TV Panel Image]]); background-repeat:no-repeat; background-position:top left;)"><img src="assets/templates/wos/images/frame.png" height="176" width="280" alt="[[+longtitle]]" border="0" /></div>
                  <div class="wslpaneldesc">[[+TV Panel Description]]</div>
                  </div>
                  • With the modified snippet I tried, I think it should work.

                    Is the name (key) of your TV actually "TV Panel Title"? Not the caption, but the name.
                      Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

                      Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
                      • 37802
                      • 11 Posts
                      Yep, you're right, I tried your new code and it works! Thank you very much.

                      But, for some reason the list of check-boxes have disappeared from the resource TV sad
                      I don't think it's your new code as I put in tje older code and they're still missing. They were definitely working fine earlier and now nothing! Very odd...