Skip to content
Interactive Decision Trees

Interactive Decision Trees

The decision-tree shortcode renders an interactive, step-by-step decision tree — one question at a time — with Back and Start Over navigation, a breadcrumb trail, and optional result links. It works in both light and dark mode.

Live Demo

Microsoft Purview Solution Finder


Usage

From a data file (recommended)

Place a JSON file in data/trees/<name>.json, then reference it by name:

{{< decision-tree data="my-tree" />}}

Enable the shortcode on the page by adding decision_tree: true to the front matter.

Inline JSON

Supply the tree structure directly inside the shortcode:

{{< decision-tree >}}
{
  "start": "q1",
  "nodes": {
    "q1": {
      "type": "question",
      "text": "Is this your first visit?",
      "options": [
        { "text": "Yes", "next": "result-new" },
        { "text": "No",  "next": "result-returning" }
      ]
    },
    "result-new": {
      "type": "result",
      "text": "Welcome! Start with the Getting Started guide.",
      "links": [{ "text": "Getting Started", "url": "/docs/" }]
    },
    "result-returning": {
      "type": "result",
      "text": "Welcome back! Check the changelog for what's new."
    }
  }
}
{{< /decision-tree >}}

Data schema

Top-level object

FieldTypeRequiredDescription
startstringYesID of the first node to display
nodesobjectYesMap of node IDs to node objects

Question node

FieldTypeRequiredDescription
typestringYesMust be "question"
textstringYesThe question text shown to the user
descriptionstringNoOptional sub-text displayed below the question
optionsarrayYesList of answer option objects (see below)

Option object (inside options)

FieldTypeRequiredDescription
textstringYesThe answer label shown on the button
nextstringYesID of the node to navigate to when selected

Result node

FieldTypeRequiredDescription
typestringYesMust be "result"
textstringYesThe result headline
descriptionstringNoHTML-safe description or recommendation text
linksarrayNoOptional list of link objects (see below)

Link object (inside links)

FieldTypeRequiredDescription
textstringYesLink label
urlstringYesURL — external links (http/https) open in a new tab automatically

Front matter

Add decision_tree: true to any page’s front matter to load the required CSS and JavaScript:

---
title: My Page
decision_tree: true
---
Last updated on