We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 10795
    • 38 Posts
    After upgrading to 2.1 or 2.1.1 I have experienced a couple snippets and packages not working anymore.

    The most common one in which I did find the solution was an easy one. It was regarding the popular Wayfinder package.
    After upgrading, my site shot an error on crashed my homepage due the use. After I re-downloaded, uninstalled the old and installed the latest package via the Package Management section. Issue fixed. Wayfinder working again.

    SOLUTION: For existing packages you have installed, after the upgrade make sure to download the latest versions and update all other and clear your cache.


    Other issues may not be so easy. And I need help on this one:

    Last time I upgraded MODx it was to 2.0.4. I remember that certain syntax regarding placeholders had been changed. In regard to the snippet that no longer works, NavigateSiblings, http://modxcms.com/forums/index.php/topic,4847.0.html
    I had updated the placeholder syntax where it was working fine with the newer 2.0.4 installation.

    Yet, now, after upgrading to 2.1.1, it no longer works?

    I still have to familiarize myself with MODx markup, it’s been awhile but logically, it’s a simple snippet and unless some syntax has been changed again, I’m not understanding why this no longer works.

    NOTE: If you look at the actual snippet use as documented in the NavigateSiblings post above, the syntax i actually use is updated to work with 2.0.4.

    Here’s the actual snippets, followed by the chunks, followed by the usage in a template that i had implemented worked fine in 2.0.4 and no longer works after upgrading to 2.1.1:

    NavigateSiblings (Snippet)
    <?php
    /**
     * NavigateSiblings
     * 
     * Flexible prev/next/parent navigation for a document with siblings.  You can
     * use it to output templated links, or just set placeholders
     * 
     * @author Jason Coward, <[email protected]>.
     * @version 1.0
     * 
     * Example usage:
     * 
     * 
     * [!NavigateSiblings? &mode=`direct`!] -- returns the output directly in place
     * of the snippet; it is assumed you are using chunk templates for this mode.
     * This is also the default mode if not specified.
     * 
     * [!NavigateSiblings? &mode=`template`!] -- sets placeholders using template
     * mode by using the default template chunk names, prevSibling, nextSibling, and
     * navSiblingsParent, and producing output to placeholders of the same name as
     * the chunk: navSiblingsPrev, navSiblingsNext, and navSiblingsParent.
     * 
     * [!NavigateSiblings? &mode=`urlonly`!] -- no output is returned, and
     * no templates are processed; instead, the snippet only sets the values of
     * placeholders for each link URL: prevSiblingUrl, nextSiblingUrl, and
     * navSiblingParentUrl.
     */
    
    /*
     * Define the mode of the snippet:
     * 
     * &mode=`template` -- will produce placeholders containing templates within
     * which the URL placeholders can be used (default mode).
     * 
     * &mode=`direct` -- will output the template chunks in the place where the
     * snippet is called within your content.
     *  
     * &mode=`urlonly` -- will only produce placeholders for the navigation URLs.
     * 
     */
    if (!isset ($mode) || ($mode !== 'template') || $mode !== 'urlonly') {
        $mode= 'direct';
    }
    
    /*
     * Define a chunk representing the presentation of the previous sibling link.
     * &prevChunk=`myPrevSiblingChunkName`
     */ 
    if (!isset ($prevChunk)) {
        $prevChunk= 'prevSibling';
    }
    
    /*
     * Define a chunk representing the presentation of the next sibling link.
     * &nextChunk=`myNextSiblingChunkName`
     */
    if (!isset ($nextChunk)) {
        $nextChunk= 'nextSibling';
    }
    
    /*
     * Determine whether or not to show a link back to the parent.
     * &showParent=`0` -- will disable this, which is set to 1 by default.
     */
    if (!isset ($showParent)) {
        $showParent= 1;
    }
    
    /*
     * Define a chunk representing the presentation of the parent link.
     * &parentChunk=`myNavParentChunkName`
     */
    if (!isset ($parentChunk)) {
        $parentChunk= 'navSiblingsParent';
    }
    
    $output= '';
    $prevOut= '';
    $parentOut= '';
    $nextOut= '';
    $parentId= (string) $modx->documentObject['parent'];
    if (!function_exists('filterNonSiblingsFromDocumentMap')) {
        function filterNonSiblingsFromDocumentMap($var) {
            global $modx;
            return (isset ($var[$modx->documentObject['parent']]));
        }
    }
    $siblings= array_filter($modx->documentMap, 'filterNonSiblingsFromDocumentMap');
    $currentKey= false;
    $prevSibling= false;
    $nextSibling= false;
    $firstSibling= current($siblings);
    $currentSibling= $firstSibling;
    while ($currentSibling !== false) {
        if (intval($currentSibling[$parentId]) === intval($modx->documentIdentifier)) {
            $currentKey= key($siblings);
            break;
        }
        $currentSibling= next($siblings);
    }
    $lastSibling= end($siblings);
    if ($currentKey) {
        if (intval($firstSibling[$parentId]) !== intval($modx->documentIdentifier)) {
            $modx->setPlaceholder('prevSiblingUrl', $modx->makeUrl($siblings[$currentKey - 1][$parentId]));
            $prevOut= !empty ($prevChunk) ? $modx->getChunk($prevChunk) : '';
        }
        if ($showParent) {
            $modx->setPlaceholder('navSiblingParentUrl', $modx->makeUrl($parentId));
            $parentOut= !empty ($parentChunk) ? $modx->getChunk($parentChunk) : '';
        }
        if (intval($lastSibling[$parentId]) !== intval($modx->documentIdentifier)) {
            $modx->setPlaceholder('nextSiblingUrl', $modx->makeUrl($siblings[$currentKey + 1][$parentId]));
            $nextOut= !empty ($nextChunk) ? $modx->getChunk($nextChunk) : '';
        }
    }
    if ($mode == 'template') {
        if (!empty ($prevChunk)) {
            $this->setPlaceholder($prevChunk, $prevOut);
        }
        if (!empty ($nextChunk)) {
            $this->setPlaceholder($nextChunk, $nextOut);
        }
        if (!empty ($parentChunk)) {
            $this->setPlaceholder($parentChunk, $parentOut);
        }
    } elseif ($mode == 'direct') {
        $output.= $prevOut . "\n";
        $output.= $parentOut . "\n";
        $output.= $nextOut . "\n";
    }
    return $output;


    Chunk example: nextSibling (Chunk)

    <a href="[[+nextSiblingUrl]]" title="Next page">NEXT PAGE</a>


    In a page template (Template)

    <div id='siblingnav'>[[NavigateSiblings? &mode=`template`]]</div>



    OK, so my questions are using this example:

    1) Has any syntax changed since v2.0.4 and if so what has changed in regard to the above example and why it no longer works?
    2) Could someone point me to a guide to current MODx syntax, preferably a compiled guide, pdf, etc for reference?
    3) A simple explanation why the above doesn’t work or if I missed something that I needed to do after the upgrade regarding my snippets.
    4) Lastly, is there an up-to-date resource (outside of other 3rd party sites, but suggestions for free resources are welcome) that has a directory of working snippets for the latest, up-to-date MODx version?

    For packages, you need to either download or update or even re-install, so I am assuming something syntactically need to be changed in old snippets now?

    Thanks for any help.
      • 3749
      • 24,544 Posts
      The syntax hasn’t changed, but a number of deprecated MODX objects and methods have been removed in 2.1, so some extras that use those deprecated items need to be updated (hopefully by their authors).

      In this case, one problem is that the $modx->documentObject array is gone, so this code won’t work:

      $parentId= (string) $modx->documentObject['parent'];
      if (!function_exists('filterNonSiblingsFromDocumentMap')) {
          function filterNonSiblingsFromDocumentMap($var) {
              global $modx;
              return (isset ($var[$modx->documentObject['parent']]));
          }
      }


      I believe this would work there:

      $parentId= (string) $modx->resource->get('parent');
      if (!function_exists('filterNonSiblingsFromDocumentMap')) {
          function filterNonSiblingsFromDocumentMap($var) {
              global $modx;
              return (isset ($var[$modx->resource->get('parent')));
          }
      }



      I’m not sure about the whole documentMap section. $modx->documentMap is also deprecated, but I think it may still be there (for now). I’m not sure if the proper thing is to use some new structure that’s replaced documentMap, create the array using xPDO, or refactor the snippet from scratch with xPDO queries.

      Just swapping out the section above is worth a try for now.

      AFAIK, that package is not up at GitHub, so I’m not sure where you’d report the problem. Hopefully, OpenGeek will see this thread.
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 10795
        • 38 Posts
        Thanks for this explanation BobRay.

        Regarding the test replacement code in post#2, it does not work. It looks like the code is just expired and non-compatible or workable with current Modx. In fact there’s quite a few different snippets out there regarding simple sibling resource navigation that don’t or won’t work anymore.

        I did find one snippet package that does address this and is located in the Extras Depository called:

        selfLink 0.1-rc1
        To navigate up, next or previous from the current resource or from the given resource

        It currently supports either using the source ’commonName’ (resource title) or a &linkText paramater to rename the text. It only supports text links though or at least I have not had the time to find out how to create a chunk that i could swap in a div,span or image. This support by passing a parameter like &linkText would really do the trick for a good solution. Maybe I can find out how in the future and submit it to the author bertoost.

        Also not sure but I couldn’t find it via package management search, so if anyone is interested you probably have to visit the actual webpage to download.

        http://modx.com/extras/package/selflink

        I’m guessing from looking around that this is the only ’up-to-date’ working snippet available for Modx 2.1+ that handles sibling nav (next, previous, and parent).