We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 33968
    • 863 Posts
    Feeling a bit silly after finding this:
    Resource List input type
    Just pass the current docid using @EVAL return $modx->resource->get(’id’); smiley

    Note however that it will list all child resources, published or not.
      • 3749
      • 24,544 Posts
      Very nice. I forgot that $modx->resource is available there.
      Allow me to suggest one change:

      $children = $modx->resource->getMany('Children', array('published' => '1'));


      That way, the query will only get published resources and you won’t have to test for that.
        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
        • 19328
        • 433 Posts
        Hello,

        I came across this thread and tried to do the same to create a dynamic resource list tv to pick a resource in the manager. However, my tv keeps showing all resources of the entire site. For you the solution in this thread seems to work, so maybe you can point me in the right direction.
        I'm using MODX Revolution 2.1.3-pl (traditional)

        My resource list tv:

        Input type: resource list
        Input option values:
        @EVAL return $modx->runSnippet('listChildren');

        Allow blank: no
        allow empty choice: no
        Parents: (left blank)
        Depth: 10
        Include parents: no
        Where conditions: (left blank)
        Limit: 0

        Output type: Default

        My snippet listChildren:

        <?php
          $children = $modx->resource->getMany('Children', array('published' => '1'));
          $output = '';
           
          $list = array();
          foreach($children as $child)
          {
             $list[]  = $child->get('pagetitle').'=='.$child->get('id');
          }
           
          $output .= implode('||',$list);
           
          return $output;
        


        Please help me if you know what the problem is with the above!!! Thanks!!


        Edit: the error log gives me two types of errors:

        Error HY093 executing statement: 
        Array
        (
            [0] => HY093
            [1] => 
            [2] => 
        )


        And a lot of this one:
        Error 42000 executing statement: 
        Array
        (
            [0] => 42000
            [1] => 1064
            [2] => You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Titel artikel==57' at line 1
        )

        [ed. note: michelle84 last edited this post 14 years, 10 months ago.]
          • 19328
          • 433 Posts
          Here I am again, apparently no one had a clue ;-).

          But I figured it out, it was super simple.
          I did not use a snippet at all, all I did was put the following in the input options field:

          @EVAL return $modx->resource->get('id');

          Left everything else as described in my post before this one.

          After all, Lucas already said it, I just didn't understand.

          Anyway, I posted this for anyone who might have the same problem.
            • 3232
            • 380 Posts
            Quote from: michelle84 at Nov 09, 2011, 12:33 PM
            Here I am again, apparently no one had a clue ;-).

            But I figured it out, it was super simple.
            I did not use a snippet at all, all I did was put the following in the input options field:

            @EVAL return $modx->resource->get('id');

            Left everything else as described in my post before this one.

            After all, Lucas already said it, I just didn't understand.

            Anyway, I posted this for anyone who might have the same problem.

            Where would you place this @eval Statement? in the parents field? I have had little success getting a document list to list the children of the current document.
              • 6038
              • 228 Posts
              Quote from: betoranaldi at Jun 13, 2012, 04:08 PM

              Where would you place this @eval Statement? in the parents field? I have had little success getting a document list to list the children of the current document.

              It's meant to go in the input option values for a tv, with the tv input type set to 'resource list'
                • 3232
                • 380 Posts
                Quote from: crunch at Jun 13, 2012, 04:19 PM
                Quote from: betoranaldi at Jun 13, 2012, 04:08 PM

                Where would you place this @eval Statement? in the parents field? I have had little success getting a document list to list the children of the current document.

                It's meant to go in the input option values for a tv, with the tv input type set to 'resource list'

                Thanks, it is a shame that it doesn't work in the parents field which would allow you to control the depth and other options. Thank you for your reply.