We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 38165
    • 19 Posts
    Hi, what I'm trying to do is explained in the title. This way I could dynamically set the parent to what I want. Here we go:

    [[!NewsPublisher@BrandStoryPub?parentid=`[[!getUrlParam? &name=`p` &int=`1` &default=`138`]]` &debug=`1`]]


    It works with the default value, but when using GET like: mysite.com/newspublisher?p=189 you get parentid value of 0 when new resource is saved.

    Running the snippets separately the outputs are correct.

    Any help or better solution greatly appreciated!

    Running MODX Cloud with MODX 2.2.8, no changes to either snippet.
    Chrome Version 27.0.1453.116 and Win 8.

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

      • 3749
      • 24,544 Posts
      You're missing the ampersand (&) on the &parentid property. wink

        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
        • 38165
        • 19 Posts
        Thanks BobRay, unfrotunately it's not that sad

        [[!NewsPublisher@BrandStoryPub? &parentid=`[[!#get.p:stripTags:default=`138`]]` &debug=`1`]]


        Also trying with fastfield now.

        P.S. BobRay you'll be getting a donation as soon as we charge the client! Thank you so much for your contributions!
          • 38165
          • 19 Posts
          Also the parents tested have been published if that should matter, propably not..

          When tested with normal value eg 117, everything works.
            • 3749
            • 24,544 Posts
            Thank you!

            I can't see any reason why that wouldn't work, but you might try using a custom snippet above the NewsPublisher snippet tag that sets a placeholder:


            <?php
            /* SetParentId snippet */
            $myParentId = isset($_GET['p'])? $_GET['p'] : 138;
            $modx->setPlaceholder('myParentId', $myParentId);
            return '';
            



            [[!SetParentId]]
            [[!NewsPublisher@BrandStoryPub? &parentid=`[[+myParentId]]` ]]



            You could also try using $_REQUEST[] instead of $_GET[].
              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
              • 38165
              • 19 Posts
              Thank you Bob!

              This is freaking weird, still doesn't work. With your snippet it sets the parent to 138 even though placeholder shows right value if I print it somewhere else.

              I gotta try this in a different setup/site. Because this is a really useful feature.

              I'll report later. Thanks!
                • 3749
                • 24,544 Posts
                You could try this in the NP tag, but I'm not sure it will make any difference:

                [[!+myParentId]]
                  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
                • discuss.answer
                  • 38165
                  • 19 Posts
                  Thanks Bob for your time! Unfortunately none of those worked.

                  Found a perfect workaround, doesn't solve the original issue, but gives a similar functionality.

                  I added Parent field to the Properties then made a copy of the inttpl with this small modification to input field.

                  <input name="[[+npx.fieldName]]" [[+npx.readonly]] class="int" id="np-[[+npx.fieldName]]" type="text"  value="[[!#get.p:stripTags:default=`[[+np.[[+npx.fieldName]]]]`]]" maxlength="[[+npx.maxlength]]" />


                  This part:

                  value="[[!#get.p:stripTags:default=`[[+np.[[+npx.fieldName]]]]`]]"


                  Works like a charm! Huuraay! smiley
                    • 3749
                    • 24,544 Posts
                    Cool solution. I'm glad you got it sorted. wink
                      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