We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 49560
    • 28 Posts
    Hey there,
    I have a small problem here (like most people here).
    Is it possible to create a dropdown of all current child recources in a migx tv?

    Example:
    Parent

    • Child Nr.1
    • Child Nr.2
    • Child Nr.3

    Should display all 3 children upon editing the tv in Parent.

    Also: Is there a list of all useable non custom inputTVtypes?

    Help would be much appreciated smiley

    This question has been answered by multiple community members. See the first response.

      Alex G - Application Development Apprentice | New MODX User
      codeblick media
    • discuss.answer
      • 4172
      • 5,888 Posts
      you can try this snippet. Name it 'getChildrenOptions'

      <?php
      
      $id = $modx->getOption('resource_id', $_REQUEST, '');
      $output = array();
      
      if (!empty($id)) {
          //if not a new resource
          if ($collection = $modx->getCollection('modResource', array('parent' => $id))) {
              foreach ($collection as $object) {
                  $output[] = $object->get('pagetitle') . '==' . $object->get('id');
              }
          }
      
      }
      
      return implode('||', $output);
      


      and put in input option values:

      @EVAL return $modx->runSnippet('getChildrenOptions');
      [ed. note: Bruno17 last edited this post 11 years, 10 months ago.]
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
      • discuss.answer
        • 4172
        • 5,888 Posts
          -------------------------------

          you can buy me a beer, if you like MIGX

          http://webcmsolutions.de/migx.html

          Thanks!
          • 49560
          • 28 Posts
          Awesome! This already helped me a lot! Thanks! laugh
          It just seems to display all parent resources instead of the children of one parent, any idea what could be wrong?

          To help further understanding:

          How the tree looks:

          • Parent 1
          • Parent 2 (where TV has to be set)
            - Child 1
            - Child 2
            - Child 3
          • Parent 3

          What I see in the dropdown:

          • Parent 1
          • Parent 2
          • Parent 3

          What I expected to see in the dropdown:

          • Child 1
          • Child 2
          • Child 3
            Alex G - Application Development Apprentice | New MODX User
            codeblick media
            • 4172
            • 5,888 Posts
            sorry, I forgot we are inside MIGX.
            Changed the code above.
              -------------------------------

              you can buy me a beer, if you like MIGX

              http://webcmsolutions.de/migx.html

              Thanks!
              • 49560
              • 28 Posts
              No problem, now it works perfectly smiley Thanks a lot!
                Alex G - Application Development Apprentice | New MODX User
                codeblick media
                • 49560
                • 28 Posts
                Another small request here: Is it possible to replace the resource ID in the table with the pagetitle?
                  Alex G - Application Development Apprentice | New MODX User
                  codeblick media
                • discuss.answer
                  • 4172
                  • 5,888 Posts
                  there are sevaral discussions/posts which handles about that request.

                  you can use the renderChunk - renderer for a new column (give it another, unused name than your resourceIdField), but then I would use the MIGX - configurator to create the configuration for that TV.
                  If you have fastField or pdoTools installed you can use fastField - tags in the renderChunk - tpl, otherwise you could use a little snippet, which gets the pagetitle from id like:

                  $output = '';
                  if ($object = $modx->getObject('modResource',$id)){
                      $output = $object->get('pagetitle');
                  }
                  return $output;


                  and call it inside the renderChunk-tpl:

                  [[getPagetitle? &id=`[[+yourResourceIdField]]`]]


                    -------------------------------

                    you can buy me a beer, if you like MIGX

                    http://webcmsolutions.de/migx.html

                    Thanks!
                    • 49560
                    • 28 Posts
                    I'll try using your snippet for now smiley

                    "+yourResourceIdField" is the field/dataIndex I suppose?

                    If so calling it with:
                    "renderer": "renderChunk-tpl"
                    doesn't work
                      Alex G - Application Development Apprentice | New MODX User
                      codeblick media
                      • 4172
                      • 5,888 Posts
                      create a MIGX - configuration in the MIGX - CMP

                      give it a name, for example 'mymigxconfig1'

                      create the formtabs and the columns
                      In the columns - creator, you can choose the renderer: this.renderChunk and put the code for the renderChunk - tpl into the textarea there.

                      Then for you MIGX-TV let the input-options for formtabs and columns empty, but fill the field 'configs' with the name of your created configuration 'mymigxconfig1'
                        -------------------------------

                        you can buy me a beer, if you like MIGX

                        http://webcmsolutions.de/migx.html

                        Thanks!