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

    I want to create a multi-select box TV that would list child resources of the current edited resource.

    I basicaly thought of doing a

    @SELECT `pagetitle` AS `name`,`id` FROM `[[+PREFIX]]site_content` WHERE `parent`= [[*id]] AND `published` = 1 AND `deleted` = 0
    


    but nothing happened. Then I didn’t find any doc or suggestion about this.

    Is there a way to achieve this ?

    Vincent
      • 19302
      • 6 Posts
      :-\

      Hey mate - I thought it would be a reasonably easy question to answer. Hopefully you’re on Revo 2.1.1.

      I thought it would be something similar to the this - https://gist.github.com/715140. Neither the snippet there or what opengeek wrote as a comment work - they return nothing. I’m pretty sure these are meant to work, as well, you should be able to run a snippet like getResources... which doesn’t work. It *could* be a bug?

      new Snippet :

      $output = "";
      
      $query = $modx->newQuery('modResource');
      $query->select(array('pagetitle', 'id'));
      $query->where(array('parent' => $modx->resource->get('id'), 'deleted' => false, 'published' => true));
      
      if ($query->prepare() && $query->stmt->execute()) {
          while ($row = $query->stmt->fetch(PDO::FETCH_ASSOC)) {
             $output .= $row['pagetitle'] . "==" . $row['id'] . "||";
          }
      }
      
      $output = trim($output, "||");
      return($output);
      


      This puts the ’pagetitle’ in the dropdown, and the selected value is the ’id’.

      Make a new template variable (listbox single select) and :

      @EVAL return $modx->runSnippet('yourSnippetName');
      


      Now, hopefully a dev can comment (lol, not on my terribad code) but on perhaps why things aren’t working in the top example?
        • 18988
        • 3 Posts
        Thank you sooooo much michael, it works perfectly. I hope this will be easier in future modx version smiley