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

    I’m trying to modify breadcrumbs snippet to fit my needs but still haven’t found how to achieve my aim

    I’m working on a multilingual project.
    I’ve created several folder each one for one language

    tree repository looks like that:


    /root(0)
    -/FR(folder) (1)
    --/A propos(folder)
    --/Produits(folder)

    -/UK(folder) (2)
    --/About us(folder)
    --/Products(folder)


    so when people are in products(UK version) they should see:

    home(as folder2 aka UK) >> products

    And not

    home(as folder0 aka Modx root) >> UK >> products

    Here are the changes to the code I’ve done:
    I’ve changed $modx->config[’site_start’] to $rootLangue which comes from UltimateParent snippet
    Changes are line 85 , 133 , 135

    full code:
    // --------------------
    // Snippet: BreadcrumbsVersion
    // --------------------
    // Version: 0.9b
    // Date: 2006.02.24
    // [email protected]
    // Honorable mentions:
    // - Bill Wilson
    // - [email protected]
    //
    // This snippet was designed to show the path through the various
    // levels of site structure back to the root. It is NOT necessarily
    // the path the user took to arrive at a given page.
    
    // Configuration Settings
    
       // $maxCrumbs [number]
       // Max number of elements to have in a path.
       // 100 is an arbitrary high number.
       // If you make it smaller, like say 2, but you
       // you are 5 levels deep, it will appear as:
       // Home > ... > Level 4 > Level 5
       // It should be noted that "Home" and the current
       // page do not count. Each of these are configured
       // separately.
       if(!isset($maxCrumbs)) $maxCrumbs = 100;
    
       // $pathThruUnPub [ true | false ]
       // When you path includes an unpublished folder, setting this to 
       // true will show all documents in path EXCEPT the unpublished.
       // Example path (unpublished in caps)
       // home > news > CURRENT > SPORTS > skiiing > article
       // $pathThruUnPub = true would give you this:
       // home > news > skiiing > article
       // $pathThruUnPub = false  would give you this:
       // home > skiiing > article (assuming you have home crumb turned on)
       if(!isset($pathThruUnPub)) $pathThruUnPub = true;
       
       // $respectHidemenu [ true | false ]
       // Setting this to true will hide items in the breadcrumb list that
       // are set to be hidden in menus.
       if(!isset($respectHidemenu)) $respectHidemenu = true;
    
       // $showHomeCrumb [true | false]
       // Would you like your crumb string to start
       // with a link to home? Some would not because
       // a home link is usually found in the site logo
       // or elsewhere in the navigation scheme.
       if(!isset($showHomeCrumb)) $showHomeCrumb = true;
    
       // $showCrumbsAtHome [ true | false ]
       // You can use this to turn off the breadcrumbs on the
       // home page.
       if(!isset($showCrumbsAtHome)) $showCrumbsAtHome = true;
    
       // $showCurrentCrumb [true | false]
       // Show the current page in path
       if(!isset($showCurrentCrumb)) $showCurrentCrumb = true;
    
       // $currentAsLink [true | false]
       // If you want the current page crumb to be a
       // link (to itself) then make true.
       if(!isset($currentAsLink)) $currentAsLink = false;
    
       // $crumbSeparator [string]
       // Define what you want between the crumbs
       if(!isset($crumbSeparator)) $crumbSeparator = "»";
    
       // $homeCrumbTitle [string]
       // Just in case you want to have a home link,
       // but want to call it something else
       if(!isset($homeCrumbTitle)) $homeCrumbTitle = 'Home';
    
       // $titleField [string]
       // To change default page field to be used as
       // a breadcrumb title, default is pagetitle
       if(!isset($titleField)) $titleField = 'menutitle';
    
       // $descField [string]
       // To change default page field to be used as
       // a breadcrumb description, default is pagetitle
       if(!isset($descField)) $descField = 'description';
    
        //Ultimate parent
        if(!isset($rootLangue)) $rootLangue = 0;
        //
    // ***********************************
    // END CONFIG SETTINGS
    // THE REST SHOULD TAKE CARE OF ITSELF
    // ***********************************
    
    // Check for home page
    if ($showCrumbsAtHome || (!$showCrumbsAtHome && ($modx->documentIdentifier != $rootLangue)) ){
    
      //initialize crumb array
      $ptarr = array();
      // get current page parent id
      $docInfo = $modx->getDocument($modx->documentIdentifier,'id,pagetitle,menutitle,published,deleted,parent,hidemenu,description');
      $pid = $docInfo['parent'];
      // show current page, as link or not
      if ($showCurrentCrumb){
        if ($currentAsLink && (!$respectHidemenu || ($respectHidemenu && $docInfo['hidemenu'] != 1 ))){
          $titleToShow = ($docInfo[$titleField])? $docInfo[$titleField] : $docInfo['pagetitle'] ;
          $descriptionToUse = ($docInfo[$descField]) ? $docInfo[$descField] : $docInfo['pagetitle'] ;
          $ptarr[] = '<a href="[~'.$modx->documentIdentifier.'~]" title="'.$descriptionToUse.'">'.$titleToShow.'</a>';
        } else {
          $ptarr[] = $docInfo['pagetitle'];
        }
      }
        // assemble intermediate crumbs
        $crumbCount = 0;
        $activeOnly = ($pathThruUnPub)? 0 : 1;
        while (($parent=$modx->getPageInfo($pid,$activeOnly,"id,pagetitle,menutitle,published,deleted,parent,hidemenu,description")) && ($crumbCount < $maxCrumbs)) {
            if ($parent['published'] && !$parent['deleted'] && $parent['id'] != $rootLangue){
                if (!$respectHidemenu || ($respectHidemenu && $parent['hidemenu'] != 1 )){
                    $titleToShow = ($parent[$titleField])? $parent[$titleField] : $parent['pagetitle'] ;
    	    $descriptionToUse = ($parent[$descField]) ? $parent[$descField] : $parent['pagetitle'] ;
                    $ptarr[] = '<a href="[~'.$parent['id'].'~]" title="'.$descriptionToUse.'">'.$titleToShow.$parent['id'].$rootLangue.'</a>';
                }
            } // end if   
            $pid = $parent['parent'];
            $crumbCount++;
        } // end while
    
        // insert '...' if maximum number of crumbs exceded
        if ($parent != 0){
            $ptarr[] = '...';
        }
    
        // add home link if desired
        if ($showHomeCrumb && ($modx->documentIdentifier != $rootLangue)){
            $ptarr[] = '<a href="[~'.$rootLangue.'~]" title="'.$homeCrumbTitle.'">'.$homeCrumbTitle.$rootLangue.'</a>';
        }
    
        $ptarr = array_reverse($ptarr);
        return join($ptarr, " $crumbSeparator ");
    
    } // end check if home page



    till now I obtain this result for Uk version

    home(UK folder) >> UK(UK folder)>>products
    with an error for first link = http://myurl/[~rootlangue~] instead of http://myurl/uk.htm

    Thx for your help

    [EDIT]

    I’d like to know how are interpreted parameters inside modx
    If I’m setting by hand in the snippet the value of rootLangue (the folder which has to be considered as the $modx->config[’site_start’]) I’m getting the right result.

    Does anybody know if the reason of my trouble could be the conversion of my parameter (integer) to a string when sent to the snippet

    And how to figure it out?

    regards

    [EDIT 2]

    Everything works fine now.
    Perhaps will it be useful to someone so Here is the fix.
    Now I’m calling UltimateParent inside the snippet with core runSnippet function

    If you set in the snippet call [[breadcrumb? &rootLangue=1]] breadcrumb will start from the ultimate parent of the document
    if not will work as usual


    // --------------------
    // Snippet: Breadcrumbs
    // --------------------
    // Version: 0.9b
    // Date: 2006.02.24
    // [email protected]
    // Honorable mentions:
    // - Bill Wilson
    // - [email protected]
    //
    // This snippet was designed to show the path through the various
    // levels of site structure back to the root. It is NOT necessarily
    // the path the user took to arrive at a given page.
    
    // Configuration Settings
    
       // $maxCrumbs [number]
       // Max number of elements to have in a path.
       // 100 is an arbitrary high number.
       // If you make it smaller, like say 2, but you
       // you are 5 levels deep, it will appear as:
       // Home > ... > Level 4 > Level 5
       // It should be noted that "Home" and the current
       // page do not count. Each of these are configured
       // separately.
       if(!isset($maxCrumbs)) $maxCrumbs = 100;
    
       // $pathThruUnPub [ true | false ]
       // When you path includes an unpublished folder, setting this to 
       // true will show all documents in path EXCEPT the unpublished.
       // Example path (unpublished in caps)
       // home > news > CURRENT > SPORTS > skiiing > article
       // $pathThruUnPub = true would give you this:
       // home > news > skiiing > article
       // $pathThruUnPub = false  would give you this:
       // home > skiiing > article (assuming you have home crumb turned on)
       if(!isset($pathThruUnPub)) $pathThruUnPub = true;
       
       // $respectHidemenu [ true | false ]
       // Setting this to true will hide items in the breadcrumb list that
       // are set to be hidden in menus.
       if(!isset($respectHidemenu)) $respectHidemenu = true;
    
       // $showHomeCrumb [true | false]
       // Would you like your crumb string to start
       // with a link to home? Some would not because
       // a home link is usually found in the site logo
       // or elsewhere in the navigation scheme.
       if(!isset($showHomeCrumb)) $showHomeCrumb = true;
    
       // $showCrumbsAtHome [ true | false ]
       // You can use this to turn off the breadcrumbs on the
       // home page.
       if(!isset($showCrumbsAtHome)) $showCrumbsAtHome = true;
    
       // $showCurrentCrumb [true | false]
       // Show the current page in path
       if(!isset($showCurrentCrumb)) $showCurrentCrumb = true;
    
       // $currentAsLink [true | false]
       // If you want the current page crumb to be a
       // link (to itself) then make true.
       if(!isset($currentAsLink)) $currentAsLink = false;
    
       // $crumbSeparator [string]
       // Define what you want between the crumbs
       if(!isset($crumbSeparator)) $crumbSeparator = "»";
    
       // $homeCrumbTitle [string]
       // Just in case you want to have a home link,
       // but want to call it something else
       if(!isset($homeCrumbTitle)) $homeCrumbTitle = 'Home';
    
       // $titleField [string]
       // To change default page field to be used as
       // a breadcrumb title, default is pagetitle
       if(!isset($titleField)) $titleField = 'menutitle';
    
       // $descField [string]
       // To change default page field to be used as
       // a breadcrumb description, default is pagetitle
       if(!isset($descField)) $descField = 'description';
    
        //Ultimate parent
        $rootLangue = isset($rootLangue) ? $modx->runSnippet('UltimateParent') : $modx->config['site_start'];
        
        //
    // ***********************************
    // END CONFIG SETTINGS
    // THE REST SHOULD TAKE CARE OF ITSELF
    // ***********************************
    
    // Check for home page
    if ($showCrumbsAtHome || (!$showCrumbsAtHome && ($modx->documentIdentifier != $rootLangue)) ){
    
      //initialize crumb array
      $ptarr = array();
      // get current page parent id
      $docInfo = $modx->getDocument($modx->documentIdentifier,'id,pagetitle,menutitle,published,deleted,parent,hidemenu,description');
      ($docInfo['parent'] != $rootLangue) ?  $pid = $docInfo['parent'] : $pid ='';
      // show current page, as link or not
      if ($showCurrentCrumb){
        if ($currentAsLink && (!$respectHidemenu || ($respectHidemenu && $docInfo['hidemenu'] != 1 ))){
          $titleToShow = ($docInfo[$titleField])? $docInfo[$titleField] : $docInfo['pagetitle'] ;
          $descriptionToUse = ($docInfo[$descField]) ? $docInfo[$descField] : $docInfo['pagetitle'] ;
          $ptarr[] = '<a href="[~'.$modx->documentIdentifier.'~]" title="'.$descriptionToUse.'">'.$titleToShow.'</a>';
        } else {
          $ptarr[] = $docInfo['pagetitle'];
        }
      }
        // assemble intermediate crumbs
        $crumbCount = 0;
        $activeOnly = ($pathThruUnPub)? 0 : 1;
        while (($parent=$modx->getPageInfo($pid,$activeOnly,"id,pagetitle,menutitle,published,deleted,parent,hidemenu,description")) && ($crumbCount < $maxCrumbs)) {
            if ($parent['published'] && !$parent['deleted'] && !($parent['id'] == $rootLangue) ){
                if (!$respectHidemenu || ($respectHidemenu && $parent['hidemenu'] != 1 )){
                    $titleToShow = ($parent[$titleField])? $parent[$titleField] : $parent['pagetitle'] ;
    	    $descriptionToUse = ($parent[$descField]) ? $parent[$descField] : $parent['pagetitle'] ;
                    $ptarr[] = '<a href="[~'.$parent['id'].'~]" title="'.$descriptionToUse.'">'.$titleToShow.'</a>';
                }
            } // end if   
            $pid = $parent['parent'];
            $crumbCount++;
        } // end while
    
        // insert '...' if maximum number of crumbs exceded
        if ($parent != 0){
            $ptarr[] = '...';
        }
    
        // add home link if desired
        if ($showHomeCrumb && ($modx->documentIdentifier != $rootLangue)){
            $ptarr[] = '<a href="[~'.$rootLangue.'~]" title="'.$homeCrumbTitle.'">'.$homeCrumbTitle.'</a>';
        }
    
        $ptarr = array_reverse($ptarr);
        return join($ptarr, " $crumbSeparator ");
    
    } // end check if home page
    
      Made with MODx : [url=http://www.copadel.com]copadel, fruits et l