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

pdoMenu

Menu generation snippet. Can replace Wayfinder and allows more flexible parameter specification.

For example, can build a menu from multiple parents at once, showing them together or as separate branches.

Significant speed gain only on first run, after that Wayfinder is not far behind, thanks to proper caching.

Parameters

Default pdoMenu accepts general pdoTools parameters and some of its own:

NameDefaultDescription
&parentsCurrent resourceList of parent ids for search, comma-separated. If you set &parents=0 - the search is not limited. If a parent ID starts with a minus, it and its children are excluded from the results.
&level0 (unlimited)Depth of the menu.
&resourcesList of resources to output in results, comma-separated. If resource id starts with minus, resource is excluded from selection.
&templatesList of template ids to filter results, comma-separated. If template id starts with minus, resources with it are excluded from selection.
&whereJSON-encoded array of extra conditions.
&displayStart0Include top-level menu nodes. Useful when specifying more than one «parents».
&contextLimit results by resource context.
&showHidden0Show resources hidden in menu.
&showUnpublished0Show unpublished resources.
&previewUnpublished0Enable preview of unpublished resources, if the user has permission.
&hideSubMenus0Hide inactive menu branches.
&selectComma-separated list of fields to select. You can specify JSON array string, e.g. &select={"modResource":"id,pagetitle,content"}
&sortbymenuindexAny resource field for sort, including TV, if it is listed in the parameter &includeTVs, e.g. &sortby={"tvname":"ASC","pagetitle":"DESC"}. You can specify JSON array string. For random sort specify &sortby=RAND()
&sortdirASCSort direction: descending or ascending. If you leave &sortby and &sortdir empty, sorting follows resource order in &resources.
&limit0Max number of results.
&offset0Number of results to skip. Must be used together with explicit &limit.
&checkPermissionsSpecify which permissions to check for user when outputting resources, e.g. &checkPermissions=list.
&countChildren0Exact count of child resources per category and output to placeholder [[+children]]. Makes extra database queries, so disabled by default.
&toPlaceholderIf not empty, snippet saves data to placeholder with this name instead of outputting.
&plPrefixwf.Prefix for pagination placeholders.
&showLog0Show extra snippet debug info. Only for users logged in to the "mgr" context.
&fastMode0Fast chunk processing mode. All unprocessed tags (conditions, snippets, etc.) will be stripped.
&cache0Snippet result caching.
&cacheTime3600Cache lifetime in seconds.
&scheme-1URL scheme, passed to modX::makeUrl(), see possible values here. Special type uri substitutes the resource uri value without calling the function.
&useWeblinkUrl1Generate URL considering resource class.
&rowIdPrefixPrefix for id="" when setting identifier in chunk.
&hereIdId of current resource for the generated menu. Only needed if the script detects it incorrectly, e.g. when outputting menu from chunk of another snippet.
&includeTVsList of TV parameters for selection, comma-separated. For example &includeTVs=action,time yields placeholders [[+action]] and [[+time]].
&prepareTVsList of TV names that use media source files, that need full paths generated. If set &prepareTVs=1, all TVs listed in &includeTVs will be prepared.
&processTVsList of TV names to process and output per Manager settings. If set &processTVs=1, all TVs listed in &includeTVs will be processed. Slows execution.
&tvPrefixPrefix for TV placeholders.

Parameters templates

These parameters set chunks that contain templates for menu generation.

NameDescription
&tplOuterChunk for the whole menu block. Default: @INLINE <ul [[+classes]]>[[+wrapper]]</ul>
&tplChunk for each menu item. If not set, resource fields will be printed to screen. Default: @INLINE <li [[+classes]]><a href="[[+link]]" [[+attributes]]>[[+menutitle]]</a>[[+wrapper]]</li>
&tplHereChunk for the current menu item.
&tplStartChunk for the root item, when is enabled &displayStart. Default: @INLINE <h2 [[+classes]]>[[+menutitle]]</h2>[[+wrapper]]
&tplParentRowChunk for a parent with children, that does not match &tplCategoryFolder. For example: @INLINE <li class="submenu_wrap [[+classnames]]"><a href="[[+link]]" [[+attributes]]>[[+menutitle]]</a>[[+wrapper]]</li>
&tplParentRowHereChunk for the current document when it has children.
&tplParentRowActiveChunk for parents with children in the active menu branch.
&tplCategoryFolderSpecial chunk for category. Category is a parent with children that has empty template or rel="category" in link_attributes field.
&tplInnerChunk for the whole submenu block. If empty - will use &tplOuter. For example: @INLINE <ul class="submenu [[+classnames]]">[[+wrapper]]</ul>
&tplInnerRowChunk for submenu item. For example: @INLINE <li class="submenu_item [[+classnames]]"><a href="[[+link]]" [[+attributes]]>[[+menutitle]]</a>[[+wrapper]]</li>
&tplInnerHereChunk for active submenu item.

CSS class parameters

These parameters set placeholder values [[+classnames]] and [[+classes]] for various menu elements. Placeholder [[+classnames]] outputs only the class name without class="" attribute, unlike [[+classes]].

NameDescription
&firstClassClass for first menu item. Default: first
&lastClassClass for last menu item. Default: last
&hereClassClass for active menu item. Default: active
&parentClassMenu category class.
&rowClassMenu item class.
&outerClassMenu block wrapper class.
&innerClassSubmenu block wrapper class.
&levelClassMenu level class. For example if you specify «level», then you get «level1», «level2», etc.
&selfClassCurrent resource class in menu.
&webLinkClassWeb link resource class.

Examples

Regular menu output from site root in one level:

modx
[[pdoMenu?
  &parents=`0`
  &level=`1`
]]

Output with exclusion of certain parents and user permission check:

modx
[[pdoMenu?
  &parents=`-10,-15`
  &level=`2`
  &checkPermissions=`load,list,view`
]]

Output menu from two parents with root nodes shown:

modx
[[pdoMenu?
  &parents=`10,15`
  &displayStart=`1`
]]

Output two levels of resources with nested count:

modx
[[pdoMenu?
  &parents=`0`
  &level=`2`
  &tplInner=`@INLINE [[+wrapper]]`
  &tplParentRow=`@INLINE <li [[+classes]]><a href="[[+link]]" [[+attributes]]>[[+menutitle]]</a> ([[+children]])</li>[[+wrapper]]`
  &countChildren=`1`
]]