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

    I’ve been through the forums so many times but cant find the answer to this.

    I cant get Ditto pagination working with phx plugin installed. I know of calling the the snippet cached and the page uncached (or is it the other way about? whatever!) but the issue I have is I am calling the snippet from a snippet (dittofilter).

    I have also tried using the ($modx->documentIdentifier != 15) in the phx plugin to disable phx on that document and yes, the pagination kicks in and works but I get weird code appearing in the head of my html page (below) which is rendered out on the page and I cant seem to work out where its coming from?

    <head>
    
    "/>`*]
    " />`*]
    
    <title>Title</title>
    


    Really need help now, at my wits end

    Thanks

      • 28042 ☆ A M B ☆
      • 24,524 Posts
      The problem is that PHx eats placeholders. They still exist in the $modx->placeholder array, though, so you can use a snippet to return $modx->getPlaceholder(’placeholder-name’) in place of the usual placeholders.

      Personally, while I think PHx is great for internal snippet use, modifying placeholders within a snippet’s chunk tpl, I never use the plugin. There is nothing at all that PHx can do that you can’t do just as quickly and easily and more reliably with a snippet, without bogging MODx down with the plugin parsing on top of the document parser (and incidentally eating all those poor innocent placeholder tags).

      For example, if I want to do something only if a logged-in manager user is viewing the page, I can use a snippet like this:
      <?php
      $breakfast = '<script type="text/javascript">
      $("#one,#two,#three,#four").dragsort({ dragSelector: "li", dragEnd: saveOrder, dragBetween: false, placeHolderTemplate: "<li></li>" });
      function saveOrder() {
          var data = new Array();
          $("div#sortable li").each(function(i, elm) { data[i] = $(elm).attr("id"); });
          $.post("[~18~]", { "ids[]": data });
      };
      </script>';
      $lunch = '<script type="text/javascript">
      $("#one,#two").dragsort({ dragSelector: "li", dragEnd: saveOrder, dragBetween: false, placeHolderTemplate: "<li></li>" });
      function saveOrder() {
          var data = new Array();
          $("div#sortable li").each(function(i, elm) { data[i] = $(elm).attr("id"); });
          $.post("[~18~]", { "ids[]": data });
      };
      </script>';
      $dinner = '<script type="text/javascript">
      $("#one, #two, #three, #four, #five").dragsort({ dragSelector: "h3", dragEnd: saveOrder, dragBetween: false });
      function saveOrder() {
          var data = new Array();
          $("div#sortable li").each(function(i, elm) { data[i] = $(elm).attr("id"); });
          $.post("[~18~]", { "ids[]": data });
      };
      </script>';
      $kids = '<script type="text/javascript">
      $("#one").dragsort({ dragSelector: "li", dragEnd: saveOrder, dragBetween: false, placeHolderTemplate: "<li></li>" });
      function saveOrder() {
          var data = new Array();
          $("div#sortable li").each(function(i, elm) { data[i] = $(elm).attr("id"); });
          $.post("[~18~]", { "ids[]": data });
      };
      </script>';
      if($_SESSION['mgrValidated']) {
          $modx->regClientStartupScript('assets/js/jquery.dragsort-0.3.10.min.js');
          $doc = $modx->documentIdentifier;
          switch ($doc) {
              case 5:
                  $modx->regClientScript($breakfast);
                  break;
              case 4:
                  $modx->regClientScript($lunch);
                  break;
              case 3:
                  $modx->regClientScript($dinner);
                  break;
              case 6:
                  $modx->regClientScript($kids);
                  break;
              default:
                  return;
          }
      }
      return;
      ?>

      It establishes the javascript necessary for implementing a drag-and-drop sorting feature to a Jot/Notes list. It makes allowances for which menu we want to be working with; they have a varying number of categories. Then it loads the appropriate javascript for the page in question if the user is a logged-in manager user.

        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
        • 3349
        • 126 Posts
        Thanks for replying Susan, was beginning to give up!

        ...so you can use a snippet to return $modx->getPlaceholder(’placeholder-name’) in place of the usual placeholders.

        So, if my pagination placeholders are contained with a Chunk like so...

        <div class="pagination">
           <p>Showing <strong>[+start+]</strong> - <strong>[+stop+]</strong> of <strong>[+total+]</strong> Properties | Page <strong>[+currentPage+]</strong> of <strong>[+totalPages+]</strong></p>
           <div id="ditto_pages"> [+previous+] [+pages+] [+next+] </div>
        </div>
        


        Do I need to generate snippets for each placeholder and call them within my Chunk? Can I do this?

        Sorry not sure I completely follow....

        bS
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          The snippet:
          <?php
          return $modx->placeholders[$ph];
          ?>

          or you can use the $modx->getPlaceholder($ph) API function, which does the exact same thing anyway.
          http://wiki.modxcms.com/index.php/API:getPlaceholder

          Then your snippet tags would look like this:
          [!getPlaceholder?ph=`start`!]


          What you see on the page where you’ve disabled PHx is the residue of the phx placeholders in your main template. The MODx parser was not able to remove the entire set of tags in its garbage collection process.
            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
            • 3349
            • 126 Posts
            In your example, what is my snippet called?

            I’ve tried what you said but the template isn’t displaying any results for the snippet call?

            Thanks
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              In the example I gave, the snippet should be named "getPlaceholder". Snippet names and the name used in the snippet tags must be exactly the same. It might be better to use a different variable name than "ph" since that might be conflicting with something PHx uses. As long as the $variable-name used in the snippet code is the same as the parameter name ?variable-name it will work.

              As a test, try this code in the snippet; it will return an array of all the placeholders available.
              echo "<pre>";
              print_r($modx->placeholders);
              echo "</pre>";
              return;
              
                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
                • 3349
                • 126 Posts
                Smashing, I’ve got pagination working now...

                However....My client wanted the pagination to appear above and below his list of properties. The pagination works fine after the ditto call but doesn’t work before it?


                <div class="pagination"><p>Showing <strong>[!myPlaceholders?myPHName=`start`!]</strong> - <strong>[!myPlaceholders?myPHName=`stop`!]</strong> of <strong>[!myPlaceholders?myPHName=`total`!]</strong> Properties | Page <strong>[!myPlaceholders?myPHName=`currentPage`!]</strong> of <strong>[!myPlaceholders?myPHName=`totalPages`!]</strong></p>
                <div id="ditto_pages"> [!myPlaceholders?myPHName=`previous`!] [!myPlaceholders?myPHName=`pages`!] [!myPlaceholders?myPHName=`next`!] </div></div>

                [!dittofilter!]

                <div class="pagination"><p>Showing <strong>[!myPlaceholders?myPHName=`start`!]</strong> - <strong>[!myPlaceholders?myPHName=`stop`!]</strong> of <strong>[!myPlaceholders?myPHName=`total`!]</strong> Properties | Page <strong>[!myPlaceholders?myPHName=`currentPage`!]</strong> of <strong>[!myPlaceholders?myPHName=`totalPages`!]</strong></p>
                <div id="ditto_pages"> [!myPlaceholders?myPHName=`previous`!] [!myPlaceholders?myPHName=`pages`!] [!myPlaceholders?myPHName=`next`!] </div></div>

                IS that because the ditto snippet hasn’t run hence there is not values to fill the placeholders called before?

                Is there any other way around this?

                Cheers