We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 33453
    • 141 Posts
    I’ve done a snippet so that long articles can be diplayed over a number of pages. Mark the point(s) in the article with a delimeter and the snippet will break the page at that point.

    The snippet call is:

    [[paginate]], which uses the default delimiter of {page}
    or
    [[paginate? &delimiter=`!!!cheese!!!`]] to specify a delimiter of !!!cheese!!!

    There are a number of issues with it as it currently stands-

    1. You can’t use the front end QuickEdit with the paginated output. Non paginated pages still work OK.
    2. TinyMCE (and possibly other RTEs) wraps the delimiter in stupid <p></p> tags. You will see I have tried and failed to strip them out in the snippet. Maybe someone with better PHP knowledge can assist here but until then you can manually remove them in the HTML view.
    3. The forward/backward page navigation need restyling, or templating.

    Anyway, I don’t want to spend any more time on it as I have many more things to do, so feel free to use it, hack it, or ignore it.

    // Get page data
    $currentid = $modx->documentObject['id'];
    $tvOutput = $modx->getTemplateVarOutput('content', $currentid);
    $content = $tvOutput['content'];
    
    // Split into separate pages
    $sdelimiter = isset($delimiter) ? "$delimiter" : "{page}";
    $pages = explode($delimiter,$content);
    $numPages = count($pages);
    
    if ($numPages>1)
    {
      // Work out where we are. Note: page numbering starts at 1
      $currentPage = isset($_GET["page"]) ? $_GET["page"]: 1;
      $prevPage = $currentPage-1;
      $nextPage = $currentPage+1;
      $pageNums = " Page $currentPage of $numPages ";
    
      // Work out links to previous and next pages
      $tvOutput = $modx->getTemplateVarOutput('alias', $currentid);
      $char = ($modx->config['friendly_urls'] == 0) ? "&" : "?";
      $link = '[~'.$currentid.'~]'.$char.'page=';
      $backlink = ($prevPage>0) ? "<a href='$link$prevPage'><--Prev</a>" : '&nbsp';
      $fwdlink = ($nextPage<=$numPages) ? "<a href='$link$nextPage'>Next--></a>" : '&nbsp';
    
      // Make links. Could use a template for this but it's a bit of an overkill
      $pageNav="<div id='pgpagenav'><p style='float:left;width:10%;text-align:right'>$backlink</p><p style='float:left;width:20%;text-align:center'>$pageNums</p><p style='float:left;width:10%;text-align:left'>$fwdlink</span></div>";
    
      // Output the page
      $output = $pages[$currentPage-1];
    #  if (substr($output, 1, 4)=="</p>") $output = substr($output, 5);
    #  if (substr($output, -3, 3)=="<p>") $output = substr($output, 1, -3);
      return "<div>$pageNums</div>".$output.$pageNav;
    }
    else return "[*#content*]";
      • 6726
      • 7,075 Posts
      Great snippet Zenmaster, this has been requested a few times in the past and will interrest a lot of people, including me smiley

      I’ll test this and report... nice snippet !
        .: COO - Commerce Guys - Community Driven Innovation :.


        MODx est l&#39;outil id
        • 33453
        • 141 Posts
        Hold on a minute - I think it’s broken!!!

        Yup - it was broken. All mended now though grin
          • 6726
          • 7,075 Posts
          Ok I’ll wait for your signal !
            .: COO - Commerce Guys - Community Driven Innovation :.


            MODx est l&#39;outil id
            • 33337
            • 3,975 Posts
            MAN! its awesome!

            Thanks for sharing.

            oh.. Zenmaster can you add proper credits in your snippet ? just like other snippets have e.g. Author, Date, contact etc.

            regards,

            zi
              Zaigham R - MODX Professional | Skype | Email | Twitter

              Digging the interwebs for #MODX gems and bringing it to you. modx.link
              • 4195
              • 398 Posts
              You made me thinking and I created a new modx plugin based on your idea.
              Check it out here. grin
                Armand Pondman
                MODx Coding Team
                :: Jot :: PHx