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

    I’m looking to write a simple function that will pull sub folder (documents) IDs and associated titles, the first level down from a specified DocID. To put this in context I then want to create a simply drop down form list using this information. I assume an array and a loop that outputs the form options is the way to approach this? Although being new to PHP I’ve no idea if this is correct.

    I realise that similar functionality is contained in the Wayfinder snippet but I’m afraid its probably beyond me to find it. Any tips on the modx calls to find these DocIDs would be appreciated.

    Cheers

    Steve
      • 24414
      • 45 Posts
      How’s about:

      getDocumentChildren
        • 6437
        • 157 Posts
        Oh dear, now I feel stupid sad .

        Thanks for that Ram, I’ve been a bit weary of delving into the API thus far so didnt pay enough attention to that part of the documentation.

        I take it that call only returns direct children? i.e. not children of children.

        Thanks again, much appreciated.

        Steve
          • 11975
          • 2,542 Posts
          As you said you could use wayfinder to create the dropdownlist

          Create a chunk named wfSelect:

          <select>
          [+wf.wrapper+]
          </select>
          


          Create a chunk named wfOption:

          <option value="[+wf.docid+]">[+wf.linktext+]</option>
          



          [!Wayfinder? &startId=`xx` &rowTpl=`wfOption` &outerTpl=`wfSelect` &level=1 !]

          I guess you could use PHx plugin to render the selected item in the list

          :-)
            Made with MODx : [url=http://www.copadel.com]copadel, fruits et l
            • 12652
            • 228 Posts
            I think I’d try it with Wayfinder first... but then again I haven’t delved into the API yet out of similar "fear & lack of knowledge" wink
              | Identity Developments delivers SEO focused web design and web presence services
              - it&#39;s not about websites, it&#39;s about your identity. |
              • 6437
              • 157 Posts
              Quote from: heliotrope at Nov 14, 2006, 02:39 PM

              As you said you could use wayfinder to create the dropdownlist

              Create a chunk named wfSelect:

              <select>
              [+wf.wrapper+]
              </select>
              


              Create a chunk named wfOption:

              <option value="[+wf.id+]">[+wf.linktext+]</option>
              



              [!Wayfinder? &startID=`xx` &rowTpl=`wfOption` &outerTpl=`wfSelect` &level=1 !]

              I guess you could use PHx plugin to render the selected item in the list

              :-)


              Ah thats an interesting approach Heliotrope - when I mentioned Wayfinder I was thinking about looking to pull the functionality from the snippet code, not to use the snippet itself - which is a much better idea smiley

              I believe I follow your example thanks - a miracle in itself really smiley My intended use of the funtion was to call it from eForm (using the built in event) to generate a form field dynamically. Would this somehow be possible using the method you describe?

              Any chance you can expand a little on the phx application please? Very curious about this as I dont quite understand but intend to use phx for other things in future.

              Quote from: identity at Nov 14, 2006, 02:45 PM

              I think I’d try it with Wayfinder first... but then again I haven’t delved into the API yet out of similar "fear & lack of knowledge" wink

              I’ve actually started to build a solution using the getDocumentChildren API call, and whilst its untested as yet with a bit of forum searching it seems that its not that difficult to implement (fingers crossed for when i actually test it out) although based on my non-existant PHP skill level I guess that Wayfinder may still be a more flexible solution.

              Once again, thanks for the tips. smiley

              Steve
                • 11975
                • 2,542 Posts
                Hi,


                with PHx plugin enabled

                Create a new Snippet (as a phx:modifier) named for instance phx:isSelected

                $global $modx;
                
                if ($output == $modx->documentIdentifier){
                 $selected =  ' selected="selected" ';
                }else{
                $selected =   '';
                }
                
                return $selected;
                
                


                Change your wfOption chunk to :

                <option value="[+wf.docid+]"[+wf.docid:isSelected+]>[+wf.linktext+]</option>
                


                Not tested but could work.

                :-)


                EDIT: Changed the placeholder [+wf.id+] to [+wf.docid+]
                  Made with MODx : [url=http://www.copadel.com]copadel, fruits et l
                  • 11975
                  • 2,542 Posts
                  This one works.

                  As wayfinder does not support PHx we have to use this syntax in wfOption chunk:


                  
                  <option value="[+wf.docid+]"[+phx:input=`[+wf.docid+]`:isSelected+]>[+wf.linktext+]</option>
                  
                  


                  And phx:isSelected

                  if($modx->documentIdentifier == $output ){
                  $selected = ' selected="selected"';
                  }else{
                  $selected = '';
                  }
                  return $selected;
                  
                  
                    Made with MODx : [url=http://www.copadel.com]copadel, fruits et l