
Product
Introducing Tier 1 Reachability: Precision CVE Triage for Enterprise Teams
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
docpad-plugin-tree
Advanced tools
DocPad plugin that when given a collection will construct a hierarchical tree of documents. Perfect for navigation menus!
DocPad plugin that when given a collection will construct a hierarchical tree of documents. Perfect for navigation menus!
$ docpad install tree
The plugin exposes a template helper, tree(collection, context, includeRoot)
, that you can use for constructing a tree of documents from any given collection:
tree(...) | Type | Description |
---|---|---|
collection | string | The name of the collection used for constructing the tree. Default: documents |
context | object | The context in which this tree is to be constructed. Will "highlight" the current document path if set. You'll typically want to set it to @document . Optional |
includeRoot | boolean | Whether or not to include the root of the collection in the constructed tree. Default: false |
For each document in the collection, you can set the following meta information:
title: "Fishing with my uncle" # Title of the page
menu: "Fishing tricks" # Title that will appear in the tree (optional)
order: 0 # Sort order
hidden: false # Whether or not to hide the item from the tree
A constructed tree will look something like this:
[
{
"title": "Some page",
"url": "/some-page",
"order": 0,
"hidden": false,
"active": false,
"current": false,
"children": [
{
"title": "A child page",
"url": "/some-page/a-child-page",
"order": 0,
"hidden": false,
"active": false,
"current": false
}
]
},
{
"title": "Parent of current page",
"url": "/parent-of-current-page",
"order": 0,
"hidden": false,
"active": true,
"current": false,
"children": [
{
"title": "Current page",
"url": "/parent-of-current-page/current-page",
"order": 0,
"hidden": false,
"active": true,
"current": true
}
]
}
]
The tree can then be used to create, say, a nested navigation menu:
<% menu = (items) => %>
<ul class="nav nav-stacked">
<% for item in items: %>
<li<%= " class=active" if item.active %>>
<a href="<%= item.url %>"><%= item.title %></a>
<%- menu item.children if item.children %>
</li>
<% end %>
</ul>
<% end %>
<%= menu @tree('html', @document) %>
You could also use it to create breadcrumbs (notice inclusion of the root):
<% trail = (items) => %>
<% for item in items: %>
<% if item.active: %>
<% if item.current: %>
<li class="active"><%= item.title %></li>
<% else: %>
<li><a href="<%= item.url %>"><%= item.title %></a></li>
<% end %>
<%- trail item.children if item.children %>
<% end %>
<% end %>
<% end %>
<ol class="breadcrumb">
<%= trail @tree('html', @document, true) %>
</ol>
Copyright © 2014 Kasper Kronborg Isager. Licensed under the terms of the MIT License.
FAQs
DocPad plugin that when given a collection will construct a hierarchical tree of documents. Perfect for navigation menus!
We found that docpad-plugin-tree demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
Research
/Security News
Ongoing npm supply chain attack spreads to DuckDB: multiple packages compromised with the same wallet-drainer malware.
Security News
The MCP Steering Committee has launched the official MCP Registry in preview, a central hub for discovering and publishing MCP servers.