We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 16545
    • 358 Posts
    It’s ok now, no more errors.

    Thx a lot!!!
      • 29774
      • 386 Posts
      Woohoo! Thanks for helping me bug fix.
        Snippets: GoogleMap | FileDetails | Related Plugin: SSL
        • 6726
        • 7,075 Posts
        It seems like a very nice addition to the repository, I’ll definitely check it out when I have more time !
        Thanks for sharing smiley
          .: COO - Commerce Guys - Community Driven Innovation :.


          MODx est l'outil id
          • 29774
          • 386 Posts
          @labasus
          Thanks for you PM about using creating dynamic select menus for eform - I thought I’d answer here so it may help someone else.

          I’ve not tried this myself but I’d think you could do it this way:
          * You’d need to prepopulate the eform with data, which can be done using the &eFormOnBeforeFormParse event. This wiki article gives an example:
          http://wiki.modxcms.com/index.php/Populate_eform_with_dynamic_data
          * The function you use to extract the data could be very similar to my Related snippet - in that you’d be using Ditto to extract the tagged values, except you’d be assigning the values to $fields instead of returning a string. $fields would appear to be an assignment by reference &$ to a variable used by eform (ie they are both point to the same value rather than being a copy, hence the function doesn’t need to return a value). Without looking into the eform code more closely I’m not sure how to represent multiple option values (presumably a multidemensional array but who knows).
          * You’d need to alter the code that builds the select options as a string, and make it populate an array instead, then assign that to $fields.

          Anyway, I’ve got a feeling the author of eform may have some better advice. Good luck!
            Snippets: GoogleMap | FileDetails | Related Plugin: SSL
            • 24530
            • 100 Posts
            Hi!

            This snippet sounds great, I have to try it soon ... but I am missing one thing: automatic backlinks. If I tell document X it is related to document Y it would be perfect, if document Y would get the information it is related to document X. Is this possible somehow?

            Thanks a lot!
              my newest webpage [url=http://gitarren.zucali.at]Meisterwerkstatt f
              • 29774
              • 386 Posts
              @raum
              Well you can simulate that behaviour using "tagData"=>"self" or"tagData"=>"ultimateParent".

              For example, let’s say you have this structure:
              Colours (20)
              --Red
              --Yellow
              --Green
              --Black
              Cars (40)
              --Audi
              --BMW
              --VW

              To list out colours on all the car pages, create a TV called ’colours’ with this as the input value, and assign to the Car template:
              $modx->runSnippet('Related', array("parents"=>"20"));
              


              To list the cars which have been tagged with the colour you’re editing in any of the colour documents, create a TV called ’cars’ and assign it to the Colours template:
              @EVAL return $modx->runSnippet('Related', array("parents"=>"40","tag"=>"colours","tagData"=>"self"));
              


              So it’s a simulation of using a xref table, but there is one important limitation to be aware of: maintaining referential integrity when deleting/moving documents. If you delete a colour then there’s no mechanism to delete the reference to it on car pages. I may write a plugin to do this at some point.
                Snippets: GoogleMap | FileDetails | Related Plugin: SSL
                • 4749
                • 623 Posts
                Mark,
                This is in reference to this thread the day you introduced Related: http://modxcms.com/forums/index.php/topic,26493.0.html When using related to generate the tv’s it returns an integer and not the name. For example, if I have a container with documents: Long, Medium, Short  and I select "Short" it will return 386 and not "Short." Here’s my call:
                <table id="master_dir" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <th scope="row">Size</th>
                    <td>[*size*]</td>
                  </tr>
                  <tr>
                    <th scope="row">Color</th>
                    <td>[*color*]</td>
                  </tr>
                  <tr>
                    <th scope="row">Shape</th>
                    <td>[*shape*]</td>
                  </tr>
                  <tr>
                    <th scope="row">Texture</th>
                    <td>[*texture*]</td>
                  </tr>
                </table>


                So, on each product page there are the TV’s automatically generated by Related. I select the values I want to show up and this is what I get:
                <table id="master_dir" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <th scope="row">Size</th>
                    <td>389</td>
                  </tr>
                  <tr>
                    <th scope="row">Color</th>
                    <td>187</td>
                  </tr>
                  <tr>
                    <th scope="row">Shape</th>
                    <td>268</td>
                  </tr>
                  <tr>
                    <th scope="row">Texture</th>
                    <td>81</td>
                  </tr>
                </table>


                Any ideas on why it would be doing that? When I had to manually enter the TV’s "Long||Medium||Short" they worked fine, but when they’re automatically generated using Related they return numbers and not the correct values.

                EDIT: Mark, I have temporarily switched to @SELECT menutitle FROM modx_site_content WHERE parent = 275. In this case it’s actually all I need, so I may end up keeping that way. I just need it to create create checkboxes as documents are created. Which, essentially, is what @SELECT was intended for. However, I do plan on using Related in the future. It’s a fabulous snippet and I intend to take advantage of it.
                  The MODx has you...
                  Utah Web Design
                  • 29774
                  • 386 Posts
                  @cbaone

                  Yes this is intentional, the relationship between two documents is based on the document ID rather than the pagetitle. The reason is that, when using tagging, if the pagetitle is changed then any links to it could potentially be lost. But why go to the bother in this instance which seems simple? Well, imagine you want to output a list of all products that have been tagged with size ’small’, or all products which are size ’large’ and color ’blue’ - either in the Manager as a TV or as part of some custom search filter on the front end. This is tagging, and so you should use be using Related  to make sure that when the client wants to change ’blue’ to ’aquamarine’ and small to ’S’, the code doesn’t break.

                  One solution would be to use a Ditto call for each of the tvs, something like this:

                  [!Ditto? &documents=`[*size*]` &depth=`1` &display=`all` &sortBy=`pagetitle` &sortDir=`ASC`&tpl=`RowTpl`!]
                  


                  However, that sucks because you’d need 4 Ditto calls. Typically if I was doing this I’d write a quick snippet to run a single Ditto call and loop through the returned values, grabbing the pagetitle using the GetField snippet. However, I appreciate this isn’t easy for everyone to do.

                  Another solution would be to use PHX to modify the tv values in the Ditto row template with a custom modifier, eg:

                    <tr>
                      <td>[+size:getPagetitle+]</td>
                      <td>[+color:getPagetitle+]</td>
                      <td>[+shape:getPagetitle+]</td>
                      <td>[+texture:getPagetitle+]</td>
                    </tr>
                  


                  The phx custom modifier, (a snippet which I’d call phx:getPagetitle) would look something like this:
                  <?php
                  $pagetitle= $modx->runSnippet('GetField', array("docid"=>$output)); // GetField returns pagetitle by default
                  return $pagetitle;
                  ?>
                  


                  You’d need to add this to your Ditto call for phx to work insdie the Ditto template:
                  &hiddenFields=`size,color,shape,texture`
                  


                  Want to give it a shot, see how it works? Or - do you think I should offer a wrapper for Ditto built into Related that does this automatically?

                  Mark
                    Snippets: GoogleMap | FileDetails | Related Plugin: SSL
                    • 4749
                    • 623 Posts
                    I think I get what you’re saying, but can get field and ditto both run in an @EVAL statement to create the TV? Hmm. Maybe I don’t follow.
                      The MODx has you...
                      Utah Web Design
                      • 29774
                      • 386 Posts
                      I meant you’d use the Ditto calls in your template. But like I say the phx route might be the way to go. You’d need to do the following:

                      * install the phx plugin (if you haven’t already)
                      * install the GetField snippet
                      * create the phx:getPagetitle snippet as described
                      * add :getPagetitle to each placeholder in your existing Ditto template
                      * add the &hiddenFields parameter to the Ditto call in your template.

                      Mark
                        Snippets: GoogleMap | FileDetails | Related Plugin: SSL