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

    i would like to sort documents like A - D, E - J etc., how would this possible to archive? could i filter a ditto-call, so that it lists all documents that start with an A, B, C & D ?
    i also found A-Z listing -> http://modxcms.com/forums/index.php?topic=5455 and ditto_atoz -> http://modxcms.com/forums/index.php/topic,29537.msg179588.html#msg179588 both seem either not  to work with modx 0.9.6.3, or i’m doing something stupidly wrong ( which is always a possibility  smiley )

    has anyone done this?

    thanks, j
      • 7231
      • 4,205 Posts
      The ditto-a2z should work with 0963...I don’t remember what version I built it on but I don’t see why it would not work. Some instructions would have been nice to include in the package...think i was busy at the time.

      OK, I found an error in the query...it is simply missing an AND in the second query and it works fine. Tis was a proof of concept rather than a ready made snippet and was built for a specific project. You need to edit the ditto call within the snippet to personalize it. THe parents and tpl can be managed directly in the snippet call but any further personalization will need to be done directly in the snippet.

      [!ditto_a2z? &parents=`0` &tpl=`tplChunkHere`!]

      To get it to work with letter range d-g you will need to modify the 2 queries a bit.

      I have attached the version with the corrected query...Ooops...don’t think i can attach files inthe forum anymore. here is a link to the corrected version
        [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

        Something is happening here, but you don't know what it is.
        Do you, Mr. Jones? - [bob dylan]
        • 26931
        • 2,314 Posts
        Thanks Shane smiley i’ll try & report
          • 26931
          • 2,314 Posts
          okay, it works smiley
          ...is it possible that i can only set one value for "&parents"? when i set &parents=`4, 5` i get an parsing error:
          « Execution of a query to the database failed - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ’ 5 LIMIT 1’ at line 1 »
          SQL: SELECT `project`.`modx_site_content`.id, `project`.`modx_site_content`.pagetitle FROM `project`.`modx_site_content` WHERE ( `projec`.`modx_site_content`.pagetitle LIKE ’A%’) AND `project`.`modx_site_content`.parent = 4, 5 LIMIT 1

          thanks, j
            • 7231
            • 4,205 Posts
            I edited the query for multiple parents. The file in the link above has been updated.

            Basically changed the parent clause from being = to using IN. I tested it with `1,2` without the space between the ids, don;t know if the space will make a difference.
              [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

              Something is happening here, but you don't know what it is.
              Do you, Mr. Jones? - [bob dylan]
              • 26931
              • 2,314 Posts
              grin brilliant! thank you so much, it works!

              i will call for each section ( A - D ...etc ) a separate ditto_a2z-snippet with the stripped-out characters for that one section, 5x

              cheers, j

                • 26931
                • 2,314 Posts
                ...okay, one (maybe 2) more question(s)  smiley

                is it possible to exclude my parent folder (or each Glossary Document ) of the Glossary? right now it shows if i select letter "A" the document "A - E" as the first result? since it is in the root, i can’t exclude parents="0", because then other documents on that level won’t be listed...

                and would it be possible to preselect the results for the first letter? so that when i go to the document "A - E" all documents under "A" are shown right away, at the moment i use a custom "noResults" template-chunk, to tell the user what to do...or would that be the more userfriendly solution anyways?

                Glossary
                A - E
                F - J
                etc.

                thanks a lot, j
                  • 7231
                  • 4,205 Posts
                  You can add standard Ditto parameters by editing (or including) parameters to the runSnippet call:

                  // run ditto snippet
                  $output = $modx->runSnippet("Ditto", array(
                  	"debug" => "0",
                  	"parents" => $parents,
                  	"depth" => "4",
                  	"display" => $display,
                  	"paginate" => "0",
                  	"paginateAlwaysShowLinks" => "0",
                  	"sortBy" => "pagetitle",
                  	"sortDir" => "ASC",
                  	"tpl" => $dittoTpl,
                  	"filter" => $filter,
                  	"tplPaginatePrevious" => "@CODE <li><a href='[+url+]'>Previous</a></li>\n",
                  	"tplPaginateNext" => "@CODE <li><a href='[+url+]'>Next</a></li>\n",
                  	"tplPaginateNextOff" => "@CODE <li><a href='[~[*id*]~]#'>Next</a></li>\n",
                  	"tplPaginatePreviousOff" => "@CODE <li><a href='[~[*id*]~]#'>Previous</a></li>\n",
                  	"tplPaginatePage" => "@CODE <li><a href='[+url+]'>[+page+]</a></li>\n",
                  	"tplPaginateCurrentPage" => "@CODE <li class='selected'><a href='[~[*id*]~]#'>[+page+]</a></li>\n",
                  	"seeThruUnpub" => "1" ));


                  You could set the parents as as unpublished and use the seeThruUnpub parameter to go into those documents to get the children without getting the parent. Untested, but it should work. If they need to be published we would need to set up additional filters for each parent...I don’t recall if Ditto has an exclude document parameter.

                  For the default option...edit this line at the top of the snippet which sets the filter to an empty string ’’:
                  $filterBy = isset($_GET["letter"]) ? strtoupper($_GET["letter"]) : "";

                  by adding a default letter if none is selected:
                  $filterBy = isset($_GET["letter"]) ? strtoupper($_GET["letter"]) : "A";


                  Let me know if this doesn’t work and I will do some testing to figure it out. wink
                    [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

                    Something is happening here, but you don&#39;t know what it is.
                    Do you, Mr. Jones? - [bob dylan]
                    • 26931
                    • 2,314 Posts
                    wohoo - grin default letters work

                    i was already playing around with ditto parameters in the snippet (setting language, noResults-tpl and adding classes to the links), but couldn’t figure out how to hide that page from the output, unfortunately i think ditto hasn’t got a don’t-show-document parameter

                    i keep on testing & let you know - again, thanks!

                    j
                      • 26931
                      • 2,314 Posts
                      You could set the parents as as unpublished and use the seeThruUnpub parameter to go into those documents to get the children without getting the parent. Untested, but it should work. If they need to be published we would need to set up additional filters for each parent...I don’t recall if Ditto has an exclude document parameter.

                      just found out, that in my case start=`1` works, since "A - E, F - J..." are always displayed first, so i can skip it... smiley
                      aaaah, of course not...it strips out the first result for every letter :-(

                      thanks, j

                      ps. if someone knows how to exclude a document with ditto, let me/us know smiley