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

pdoCrumbs

Snippet for building breadcrumb navigation.

Replaces BreadCrumb well, works with documents from any contexts and allows specifying various conditions for resource selection.

Snippet has high performance by selecting all needed elements from the database in a single query.

Parameters

Accepts all pdoTools parameters and some of its own:

ParameterDefaultDescription
&showLog0Show extra snippet debug info. Only for users logged in to the "mgr" context.
&from0Resource id from which to build breadcrumbs. Usually the site root, i.e. «0».
&toResource id for which breadcrumbs are built. Default is current page id.
&excludeList of resource IDs to exclude from selection.
&toPlaceholderIf set, the snippet stores all data in a placeholder with this name instead of outputting.
&outputSeparator\nSeparator between crumbs
&tplName chunk for displaying resource. If not set, resource fields will be printed to screen.
&tplCurrentChunk for formatting current document in navigation.
&tplMaxChunk added at the start of results if there are more than &limit.
&tplHomeChunk for formatting link to home page.
&tplWrapperWrapper chunk for all results. Accepts one placeholder: [[+output]]. Does not work with the parameter &toSeparatePlaceholders.
&wrapIfEmptyEnables wrapper chunk output &tplWrapper even when no results.
&showCurrent1Output current document in navigation.
&showHome0Output link to home at start of navigation.
&showAtHome1Show breadcrumbs on the site home page.
&hideSingle0Don't output result if it is the only one.
&directionltrNavigation direction: left to right «ltr» or right to left «rtl», e.g. for Arabic.

Templates

TemplateDefault
&tpl@INLINE <li><a href="[[+link]]">[[+menutitle]]</a></li>
&tplCurrent@INLINE <li class="active">[[+menutitle]]</li>
&tplMax@INLINE <li class="disabled">&nbsp;...&nbsp;</li>
&tplHome
&tplWrapper@INLINE <ul class="breadcrumb">[[+output]]</ul>

Examples

Generate breadcrumbs for current page:

modx
[[pdoCrumbs]]

Generate with limit on number of items:

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

Snippet works well when called from pdoResources. For example, this chunk:

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

Generate Schema.org microdata in JSON-LD format

fenom
{'!pdoCrumbs' | snippet: [
  'showHome' => 1,
  'tplWrapper' => '@INLINE
    <script type="application/ld+json">
      {
        "@context": "http://schema.org",
        "@type": "BreadcrumbList",
        "itemListElement": [ {$output} ]
      }
    </script>
  ',
  'tplHome' => '@INLINE
    {
      "@type": "ListItem",
      "position": {$idx},
      "item": {
        "@id": "{$link}",
        "name": "{$menutitle}"
      }
    },
  ',
  'tplCurrent' => '@INLINE
    {
      "@type": "ListItem",
      "position": {$idx},
      "item": {
        "@id": "{$link}",
        "name": "{$menutitle}"
      }
    }
  ',
  'tpl' => '@INLINE
    {
      "@type": "ListItem",
      "position": {$idx},
      "item": {
        "@id": "{$link}",
        "name": "{$menutitle}"
      }
    },
  ',
]}

Demo

Working example of breadcrumb generation in search results mSearch2.

Demo