We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 30623
    • 9 Posts
    I have a unique hack for TVs that I am implementing incorrectly. A college lists courses and wants to manually select the faculty when they edit the resource for the course page.

    To generate a dynamic list of faculty, I am using checkboxes with an @SELECT binding to grab the id of faculty resources and store them as TVs. This works fine.

    @SELECT pagetitle,id FROM modx_site_content where parent=109 order by pagetitle ASC
    


    The problem is that the TV values are storing the content ID with the delimiter || and I use ditto to create lists of the courses for each faculty member.

    [!Ditto? &parents=`50,396,304` &filter=`facultyTV,[+id+],9` &tpl=`course_list` &noResults=`empty_chunk` !]
    


    When Ditto filters the results, it doesn’t pay attention to the delimiters and just looks for strings that match my id. For instance, when Ditto is looking for only the id "151" it returns true when it sees 331||513

    Clearly, I can’t make Ditto do this, but I’m hoping someone has a better suggestion for how to achieve this with TVs. I want to return all the courses for each faculty member and output as a chunk, but not sure how else to do this other than Ditto without writing some custom snippet. Is there an easier way?

      • 4310
      • 2,310 Posts
      You could use a snippet (FilterIds) like this:
      <?php
      $output = '';
      $TVarray = $modx->getTemplateVarOutput(array('facultyTV'));
      if(!empty($TVarray['facultyTV'])){ 
      $values = $TVarray['facultyTV'];
      $tv_ids = explode('||', $values); 
      foreach($tv_ids as $single_id){
      $output .= ''.$single_id.',[+id+],9|';
      }
      }
      return $output;
      ?>

      Then have a Ditto call :
      [!Ditto? &parents=`50,396,304` &filter=`[[FilterIds]]` &tpl=`course_list` &noResults=`empty_chunk` !]

      Untested but could be one approach.
        • 30623
        • 9 Posts
        David,

        I appreciate for the reply. Not sure why the forums didn’t email when you posted this, but am just getting to it today.

        This solution didn’t quite work, but it seems that I will have to work on a custom snippet.

        Anyway, thanks for the effort.

        Patrick
          • 4310
          • 2,310 Posts
          You could try adding &debug=`1` to the call to see what’s happening.