We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 40088
    • 708 Posts
    I understand the &parentid but instead of a static resource I would like to give the user the ability to select from a list of categories to publish their resource to.

    On the npOuterTpl (well, a duplicate of that tpl) I added a <select> element using getResources to generate a list of available containers,
    <select name="pub_parent" id="parent">
    [[!getResources?
    	&parents=`2`
    	&tpl=`NP Parent`
    	&where=`{"isfolder:=":"1"}`
    	&depth=`4`
    	&sortby=`alias`
    	&sortdir=`ASC`
    	&limit=`0`
    	&includeContent=`0`
    	&resources=`-33`
    ]]
    </select>
    

    The &tpl=`NP Parent` (above) is,
    <option[[!getReqParam:is=`[[+id]]`:then=`selected="selected"`:else=``? &name=`parent`]] value="[[+id]]">[[+pagetitle]]</option>

    Then in the NP call I used getReqParam to set the &parentid,
    &parentid=`[[!getReqParam? &name=`pub_parent`]]`

    The NP form submits (no errors) but the resource is created in the wrong section (in the same area as the NP form).

    This question has been answered by BobRay. See the first response.

    [ed. note: todd.b last edited this post 11 years, 9 months ago.]
      Todd
      • 3749
      • 24,544 Posts
      The &parentId needs to be an integer, so the odds of that working are pretty slim to begin with, and even if it could work, output modifiers nested that deeply almost never function properly.

      If you skip getResources and just write a custom snippet to return a comma-separated list of the IDs you want in the drop down, then set &parent to the one you want selected (with another snippet if necessary), it should do what you want.

      [[!NewPublisher?
         &parents=`[[getParents? &parent=`2`]]`
         &parentId=`12`
      ]]


      Something like this:

      /* getParents snippet */
      $parentId = $modx->getOption('parent', $scriptProperties, '');
      $parentObj = $modx->getObject('modResource', $parentId);
      
      if ($parentObj) {
          $final = array();
          $final[] = $parentId;  /* Might not want this it includes
                                    the parent id in the list */
          $docs = $parentObj->getMany('Children');
      
          foreach ($docs as $doc) {
              $docId = (int) $doc->get('id');
              if ($doc->get('isfolder') && ($docId != 33)) {
                  $final[] = $doc->get('id');
              }
          }
      }
      
      return implode(",", $final);
      
      [ed. note: BobRay last edited this post 11 years, 9 months ago.]
        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
        • 40088
        • 708 Posts
        Thanks, I'll try your suggestion and see what happens.

        Out of curiosity and going back to my original example above, I'm trying to understand why it can't be tweaked to pass an integer. It really seems like it could/should work.
          Todd
          • 40088
          • 708 Posts
          Bob, I tried your example but my NP form page goes blank. Also, I'm confused about the &parentId=`12` in your example. What parent is it supposed to represent? It looks like you're hard-coding a parent when I thought it was to be dynamically generated.

          Here's what I did:

          1. Created a 'getParents' snippet using your code.
          2. Replaced the [[getResources? ...]] call with [[getParents]].
          3. Added &parents=`[[getParents? &parent=`2`]]` &parentId=`2` to the NP call.
          4. *** NP page is blank.
            Todd
          • discuss.answer
            • 3749
            • 24,544 Posts
            I used 12 as an example. The &parent property sets the member in the drop-down that is selected. What do you want it to be? If you want it to be the current resource, use &parent='[[*id']].


            For now, try hard-coding everything like this:

            [[!NewsPublisher? 
                &parentIds=`3,12,24,35,46`
                &parent=`12` 
                etc. . . 
            ]]
            


            Make sure the parent is in the parentId list.
              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
              • 40088
              • 708 Posts
              Going back to your getParents snippet, when pasted into the Ace editor it throws an error on line 13, Syntax error, unexpected '}'. Removing it does nothing.
                Todd
                • 3749
                • 24,544 Posts
                It was missing the final semicolon on line 11. Fixed above.
                  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
                  • 40088
                  • 708 Posts
                  Unfortunately it still results in a blank NP form page. And the alternative hard-coded example above doesn't seem to work either.

                  Thanks for fixing the typo.
                    Todd
                    • 3749
                    • 24,544 Posts
                    Quote from: todd.b at Dec 23, 2014, 10:54 PM
                    the alternative hard-coded example above doesn't seem to work either.

                    What happens when you try it? You did change the ids to match real, published resources, right?
                      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
                      • 40088
                      • 708 Posts
                      A blank page. Correct, the ids point to actual published resources.

                      Clearly I'm doing something I shouldn't; parts in wrong place etc. The hard-coded method does not require the getParents snippet, correct?
                        Todd