We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 30912
    • 463 Posts
    I'm following the tutorial for a multi select box from http://rtfm.modx.com/display/revolution20/Creating+a+multi-select+box+for+related+pages+in+your+template Which i can get to work fine without including any TV's but becuase I intent to give the client the ability to select the case studies we've decided to pretty it up.

    Ive read the article at: https://forums.modx.com/thread/70587/display-resources-selected-through-tv-urgent but I cannot make that work for multiple TV's in the chunk and i;m not sure what im missing.

    As it stands at the minute with the modified call below, no items are listed in the TV select box.

    My calls and TPL are as follows:

    Snippet: ListCaseStudies - based on the above example in the forum post
    if (empty($input)) { return 'This article is so unique, that we couldn\'t find anything related to it!'; }
    $tpl = $modx->getOption('tpl',$scriptProperties,'CaseStudyTpl');
    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) {
        $fields = $resource->toArray();
        $fields['Case-Study-Image'] = $resource->getTVValue('Case-Study-Image');
      $fields['Case-Study-Title'] = $resource->getTVValue('Case-Study-Title');
      $fields['Case-Study-Intro'] = $resource->getTVValue('Case-Study-Intro');
        $output[] = $modx->getChunk($tpl,$fields);
      }
    }
    return implode('',$output);


    CaseStudyTpl

     <div class="boxgrid caption" onclick="location.href='[[~[[+id]]]]';" style="cursor:pointer;"> 
    
    <img src="[[+Case-Study-Image]]" alt="[[+Case-Study-Title]]" />
    <div class="cover boxcaption">
    <h3>[[+Case-Study-Title]]</h3>
    <p>[[+Case-Study-Intro]]</p>
    [[+pagetitle]] <!-- Added for testing purposes -->
    </div>


    TV eval call

    @EVAL return $modx->runSnippet('ListCaseStudies',array('parent' => 10));


    INput:

    [[*Case_Study:is=``:then=``:else=`<div class="case-study">
              <div class="case-study-title">Case studies</div>
              <div class="case-study-content"> [[ListCaseStudies? &input=`[[*Case_Study]]` &tpl=`CaseStudyTpl` ]]</div>


    Any help would be apprecaited as i suck at snippets.

    I know theres getRelated but i havent worked with that yet so... [ed. note: Tyreal2012 last edited this post 14 years, 4 months ago.]
      • 3749
      • 24,544 Posts
      Where is $input coming from? I don't see anything wrong offhand, but I would use a different variable name unless this is an output modifier, because MODX sets an $input variable for use in output modifiers.


      ------------------------------------------------------------------------------------------
      PLEASE, PLEASE specify the version of MODX you are using.
      MODX info for everyone: http://bobsguides.com/modx.html
        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
        • 30912
        • 463 Posts
        The input would help yes, I've added it above.
          • 3749
          • 24,544 Posts
          I'm afraid I can't really follow what you're trying to do, but it sure seems like there should be a simpler way to do it that would lead to much faster page loads.

          For one thing, using @EVAL/runSnippet in a TV is almost never necessary, IMO. @EVAL is slow and insecure and runSnippet adds an unnecessary function call.

          Maybe I'm missing something, but it seems the tag for this TV:

          @EVAL return $modx->runSnippet('ListCaseStudies',array('parent' => 10));


          Could be replaced with a snippet tag

          [[ListCaseStudies? &parent=`10`]]


          (BTW, I don't see the snippet using the parent value anywhere).


          For another, as I said, I would change the name of the $input variable.


          Hope this helps.


          ------------------------------------------------------------------------------------------
          PLEASE, PLEASE specify the version of MODX you are using.
          MODX info for everyone: http://bobsguides.com/modx.html

            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
            • 30912
            • 463 Posts
            I need to use the @EVAL as its listing a set of documetn from a set parent in this case 10, as i say the snippet works fine from the example in the RTFM, but it only brings through page titles and otehr standard fields, what i need it to do is to bring through TV values as well.

            As i say - i suck at snippets, so changing the input means nothing to me smiley

            Seen a MarkH added the RTFM perhaps this is his area or someone who has done similar...unless it would help to systematically write out what i want to achieve?

            Thanks for the help so far.


              • 3749
              • 24,544 Posts
              Yes, Mark Hamstra would really be the person to help you with this, since he wrote the tutorial.


              ------------------------------------------------------------------------------------------
              PLEASE, PLEASE specify the version of MODX you are using.
              MODX info for everyone: http://bobsguides.com/modx.html
                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