We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 16183
    • 1,390 Posts
    Would an answer be here?

    http://www.pogwatch.com/ditto/ditto-filters.html

    cheers/k
      • 26931
      • 2,314 Posts
      hi kongondo,

      thanks for that link (fodder for my ever growing, never ending, scarily unordered list of modx-bookmarks wink ), i’ve already tried some of those filters...i guess, i’m diving right back in smiley

      j
        • 7231
        • 4,205 Posts
        I think that adding a filter to exclude documents that are containers might do it...not sure if Ditto will exclude onl the parent or the children as well. You can also use PHx in the TPL to check for this (or any other criteria) and display accordingly.
          [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
          hola  smiley

          I think that adding a filter to exclude documents that are containers might do it...not sure if Ditto will exclude onl the parent or the children as well. You can also use PHx in the TPL to check for this (or any other criteria) and display accordingly.

          ...ditto-filters probably don’t work here (i’ve tried), because &filter is set and already used by the variable $filter in the snippet-code, or is it somehow possible to apply more than one filter?

          filtering by template would probably do the trick for me, as i’m just using 2

          thanks, j

          *edit: ...oh yes, you can apply several filters separated by "|" ...i’ll check and report...
            • 26931
            • 2,314 Posts
            i got it...

            i increase the variable $filter with a second clause -> $filter = "pagetitle,".$filterBy.",11|id,146,2";
            so the document with the id of 146 will be excluded smiley
              • 7231
              • 4,205 Posts
              Cool, glad you got it working...we can polish this ’wrapper snippet’ to make it more user friendly and allow more configuration directly from the snippet call at some point.
                [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
                absolutely laugh

                i just began learning php...got me a new book, the old one i borrowed, had so many typos in it, that half the time i kept wondering if it was on purpose that a certain comma, or bracket was missing...
                • I haven’t bought a book for years, but I did get myself a Xerox laser printer...

                  http://devzone.zend.com/node/view/id/627 - I originally learned from this one!
                  http://devzone.zend.com/public/view
                  http://www.onlamp.com/php/
                  http://www.devshed.com/c/b/PHP/
                  http://www.melonfire.com/community/columns/trog/archives.php?page=9&category=PHP

                  I’m especially fond of this guy’s tutorials http://www.oreillynet.com/pub/au/135
                  Here’s a good site for finding tutorials http://www.goodphptutorials.com/tag/all/beginner+tutorials?sort=pop

                    Studying MODX in the desert - http://sottwell.com
                    Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                    Join the Slack Community - http://modx.org
                    • 26931
                    • 2,314 Posts
                    I haven’t bought a book for years, but I did get myself a Xerox laser printer...

                    http://devzone.zend.com/node/view/id/627 - I originally learned from this one!
                    http://devzone.zend.com/public/view
                    http://www.onlamp.com/php/
                    http://www.devshed.com/c/b/PHP/
                    http://www.melonfire.com/community/columns/trog/archives.php?page=9&category=PHP

                    I’m especially fond of this guy’s tutorials http://www.oreillynet.com/pub/au/135
                    Here’s a good site for finding tutorials http://www.goodphptutorials.com/tag/all/beginner+tutorials?sort=pop

                    ;D wow - thanks a lot, that’s great! j
                      • 26931
                      • 2,314 Posts
                      Hi everyone,

                      got a little problem with the A2Z Snippet ...

                      e.g. if i got a site structure like

                      - res (id2)
                      - sub res01
                      - sub res02
                      - sub res03 (id4)
                      --- subsub01
                      --- subsub02
                      - sub res03
                      - sub res04

                      and call the Snippet [!A2Z? &parents=`2`!] it doesn’t grab the ressources within container "sub res03(id4)" automatically, although the Ditto parameters within the Snippet say so ... if i add the container id to the Snippet call [!A2Z? &parents=`2,4`!] it works.
                      + if i declare the letter which should be used as default:
                      $filterBy = isset($_GET["letter"]) ? strtoupper($_GET["letter"]) : "A";
                      and the only ressource starting with an "A" is within container(id4), the Snippet will list the ressource, but not display letter "A" as an active link within the A to Z listing at the top -> see screenshot below
                      if i move the ressource one level up (direct child of id2) it works.

                      this is the Snippet code in use:
                      <?php
                      $docid = $modx->documentIdentifier;
                      $parents = isset($parents) ? $parents : $docid;
                      $dittoTpl = isset($tpl) ? $tpl : "a2z-template"; // ditto tpl to use
                      $display = isset($display) ? $display : "all"; // number of items per page to return
                      $filterBy = isset($_GET["letter"]) ? strtoupper($_GET["letter"]) : "A";
                      $filter = "pagetitle,".$filterBy.",11";
                      
                      //-- Alphabet Letters
                      $letter = array (
                      	"A",
                      	"B",
                      	"C",
                      	"D",
                      	"E",
                      	"F",
                      	"G",
                      	"H",
                      	"I",
                      	"J",
                      	"K",
                      	"L",
                      	"M",
                      	"N",
                      	"O",
                      	"P",
                      	"Q",
                      	"R",
                      	"S",
                      	"T",
                      	"U",
                      	"V",
                      	"W",
                      	"X",
                      	"Y",
                      	"Z"
                      );
                      
                      $table = $modx->getFullTableName("site_content");
                      
                      foreach($letter as $l){
                      	$sql = "SELECT $table.id, $table.pagetitle FROM $table WHERE ( $table.pagetitle LIKE '$l%') AND ($table.parent IN ($parents)) LIMIT 1";
                      	$results = $modx->db->query($sql);
                      	$count = $modx->db->getRecordCount( $results );
                      	if ($count > 0) {
                          	$letters .= "<a href=\"[~".$docid."~]?letter=".$l."\">".$l."</a>";
                      	} else {
                          	$letters .= "<span>" . $l . "</span>";
                      	}
                      }
                      
                      // get count for pagination
                      $v = '';
                      if($filterBy != ""){
                      	$sql = "SELECT $table.id, $table.pagetitle FROM $table WHERE ( $table.pagetitle LIKE '$filterBy%') AND ($table.parent IN ($parents))";
                      	$results = $modx->db->query($sql);
                      	$v = $modx->db->getRecordCount( $results );
                      }
                      // 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,
                              "language" => "german",
                      	"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" ));
                      
                      //$v = count($output);
                      
                      // $modx->setPlaceholder('a2zletters', $letters);
                      $modx->setPlaceholder('a2z', $output);
                      $modx->setPlaceholder('pages', $pages);
                      return "<p class=\"lexicon\">".$letters."</p> ".$output.$pages;
                      ?>

                      can anyone spot in the Snippet code why ressources within the subfolder aren’t displayed?
                      btw. i also tried different caching options without success.

                      thanks, j