Skip to content
  1. Extras
  2. pdoTools
  3. Snippets
  4. pdoCrumbs

pdoCrumbs

Snippet for building breadcrumb-style navigation.

Good substitute for BreadCrumb works with documents from any contexts and provides a number of options for selecting resources.

Snippet has a very high speed, due to selecting only the specified elements from the database per request .

Properties

Accepts all of the properties of [pdoTools] 2 and some others:

PropertyDefaultDescription
&showLog0Show additional information on the work of the snippet . Only displayed to users logged in to the «mgr» context.
&from0Id of the resource from which to begin to build the breadcrumbs . This is usually the root of the site, which is "0".
&toId of the resource with which end the breadcrumbs . By default, the id of the current page.
&excludeComma-separated list of resource IDs that should be excluded from the output.
&toPlaceholderIf not empty, the snippet will save all data to a placeholder with the same name , instead of displaying the output to the screen.
&outputSeparator → The character to use as a separator between the crumbs.
&tplName of chunk for formatting the output. If not specified, the contents of the resource fields will be printed to the screen.
&tplCurrentChunk for formatting the current resource's crumb in the navigation .
&tplMaxChunk which is added to the end of the results, if there are more than &limit crumbs.
&tplHomeChunk for formatting the link on the home page.
&tplWrapperChunk for formatting the wrapper, to wrap all results. Provides one placeholder: [[+output]]. It does not work in conjunction with &toSeparatePlaceholders.
&wrapIfEmptyOutput the chunk wrapper &tplWrapper even if there are no results.
&showCurrent1Display the current document in the navigation.
&showHome0Display a crumb for the home page.
&showAtHome1Show breadcrumbs on the home page.
&hideSingle0Do not display the result if it is only a single crumb.
&directionltrThe direction of navigation: from left to right «ltr» or right to left «rtl», such as for Arabic.

Template Properties

TemplateDefault
&tpl@INLINE <a href="[[+link]]">[[+menutitle]]</a>
&tplCurrent@INLINE <span>[[+menutitle]]</span>
&tplMax@INLINE <span>&nbsp;...&nbsp;</span>
&tplHome
&tplWrapper@INLINE <div class="breadcrumbs">[[+output]]</div>

Examples

Generation of bread crumbs for the current page:

modx
[[pdoCrumbs]]

Generation of a restricted number of items:

modx
[[pdoCrumbs?
  &limit=`2`
]]

Snippet works well when called from pdoResources. For example, here is a chunk:

modx
<h3>[[+pagetitle]]</h3>
<p>[[+introtext]]</p>
[[pdoCrumbs?
  &to=`[[+id]]`
  &showCurrent=`0`
]]

Generating page headers

pdoCrumbs can be called inside another snippet, for example, to generate the header tag of your pages.

Snippet Title:

php
<?php
// We define variables
if (empty($separator)) {$separator = ' / ';}
if (empty($titlefield)) {$titlefield = 'longtitle';}
if (empty($parents_limit)) {$parents_limit = 3;}
if (empty($tplPages)) {$tplPages = 'No. [[+page]] of [[+pageCount]]';}

// Key and cache settings
$cacheKey = $modx->resource->getCacheKey() . '/title_' . sha1(serialize($_REQUEST));
$cacheOptions = array('cache_key' => 'resource');

if (!$title = $modx->cacheManager->get($cacheKey, $cacheOptions)) {
  // We learn the name of the page
  $title = !empty($modx->resource->$titlefield)
    ? $modx->resource->$titlefield
    : $modx->resource->pagetitle;

  // Add a search query, if there is one
  if (!empty($_GET['query']) && strlen($_GET['query']) > 2) {
    // We need to use a placeholder to avoid
    $title .= ' «[[+mse2_query]]»';
  }

  // Adding pagination if indicated
  if (!empty($_GET['page'])) {
    $title .= $separator . str_replace('[[+page]]', intval($_GET['page']), $tplPages);
  }

  // Adding parents
  $crumbs = $modx->runSnippet('pdoCrumbs', array(
    'to' => $modx->resource->id,
    'limit' => $parents_limit,
    'outputSeparator' => $separator,
    'showHome' => 0,
    'showAtHome' => 0,
    'showCurrent' => 0,
    'direction' => 'rtl',
    'tpl' => '@INLINE [[+menutitle]]',
    'tplCurrent' => '@INLINE [[+menutitle]]',
    'tplWrapper' => '@INLINE [[+output]]',
    'tplMax' => ''
  ));
  if (!empty($crumbs)) {
    $title = $title . $separator . $crumbs;
  }

  // By caching the results
  $modx->cacheManager->set($cacheKey, $title, 0, $cacheOptions);
}

// return title
return $title;

Call the snippet on the page

modx
<title>[[Title]] / [[++site_name]] - my best website in the world</title>

Demo

Working Example [generate breadcrumbs in the search results] 3 mSearch2.

Also the site bezumkin.ru uses dynamic titles.