Skip to content

Runtime API Examples

This page demonstrates usage of some of the runtime APIs provided by VitePress.

The main useData() API can be used to access site, theme, and page data for the current page. It works in both .md and .vue files:

md
<script setup>
import { useData } from 'vitepress'

const { theme, page, frontmatter } = useData()
</script>

## Results

### Theme Data
<pre>{{ theme }}</pre>

### Page Data
<pre>{{ page }}</pre>

### Page Frontmatter
<pre>{{ frontmatter }}</pre>

Results

Theme Data

{
  "search": {
    "provider": "local"
  },
  "editLink": {
    "pattern": "https://github.com/phlex-ruby/phlex.fun/edit/main/:path"
  },
  "nav": [
    {
      "text": "Home",
      "link": "/"
    },
    {
      "text": "Docs",
      "link": "/introduction"
    },
    {
      "text": "Support",
      "link": "https://github.com/orgs/phlex-ruby/discussions"
    },
    {
      "text": "v1 Docs",
      "link": "https://v1.phlex.fun"
    }
  ],
  "sidebar": [
    {
      "text": "Project",
      "collapsed": false,
      "items": [
        {
          "text": "Community",
          "link": "/project/community"
        },
        {
          "text": "GitHub",
          "link": "https://github.com/phlex-ruby"
        }
      ]
    },
    {
      "text": "Introduction",
      "collapsed": false,
      "items": [
        {
          "text": "Overview",
          "link": "/introduction/"
        },
        {
          "text": "Getting started",
          "link": "/introduction/getting-started"
        }
      ]
    },
    {
      "text": "Components",
      "collapsed": false,
      "items": [
        {
          "text": "Rendering",
          "link": "/components/rendering"
        },
        {
          "text": "Yielding",
          "link": "/components/yielding"
        },
        {
          "text": "Kits",
          "link": "/components/kits"
        },
        {
          "text": "Caching",
          "link": "/components/caching"
        },
        {
          "text": "Fragments",
          "link": "/components/fragments"
        },
        {
          "text": "Streaming",
          "link": "/components/streaming"
        },
        {
          "text": "Snippets",
          "link": "/components/snippets"
        },
        {
          "text": "Testing",
          "link": "/components/testing"
        }
      ]
    },
    {
      "text": "HTML & SVG",
      "collapsed": false,
      "items": [
        {
          "text": "HTML elements",
          "link": "/sgml/html-elements"
        },
        {
          "text": "SVG elements",
          "link": "/sgml/svg-elements"
        },
        {
          "text": "Attributes",
          "link": "/sgml/attributes"
        },
        {
          "text": "Text",
          "link": "/sgml/text"
        },
        {
          "text": "Whitespace",
          "link": "/sgml/whitespace"
        },
        {
          "text": "Comments",
          "link": "/sgml/comments"
        },
        {
          "text": "Raw output",
          "link": "/sgml/raw"
        },
        {
          "text": "Doctype (HTML only)",
          "link": "/sgml/doctype"
        },
        {
          "text": "Helpers",
          "link": "/sgml/helpers"
        }
      ]
    },
    {
      "text": "Rails",
      "collapsed": false,
      "items": [
        {
          "text": "Adopting Phlex",
          "link": "/rails/adopting-phlex"
        },
        {
          "text": "Helpers",
          "link": "/rails/helpers"
        },
        {
          "text": "Views",
          "link": "/rails/views"
        },
        {
          "text": "Layouts",
          "link": "/rails/layouts"
        }
      ]
    },
    {
      "text": "Miscellaneous",
      "collapsed": false,
      "items": [
        {
          "text": "Literal Properties",
          "link": "/miscellaneous/literal-properties"
        },
        {
          "text": "Under the hood",
          "link": "/miscellaneous/under-the-hood"
        },
        {
          "text": "Upgrading to v2",
          "link": "/miscellaneous/v2-upgrade"
        },
        {
          "text": "Structural Safety",
          "link": "/miscellaneous/structural-safety"
        }
      ]
    },
    {
      "text": "Technical Design",
      "collapsed": true,
      "items": [
        {
          "text": "Attribute Caching",
          "link": "/design/attribute-caching"
        }
      ]
    },
    {
      "text": "AI Prompt",
      "link": "/ai"
    }
  ],
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://github.com/phlex-ruby"
    }
  ],
  "footer": {
    "message": "Released under the MIT License.",
    "copyright": "Made by <a href=\"https://joel.drapper.me\">Joel Drapper</a>, <a href=\"https://github.com/willcosgrove\">Will Cosgrove</a> and dozens of other <a href=\"https://github.com/phlex-ruby/phlex/graphs/contributors\">contributors</a>."
  }
}

Page Data

{
  "title": "Runtime API Examples",
  "description": "",
  "frontmatter": {
    "outline": "deep"
  },
  "headers": [],
  "relativePath": "api-examples.md",
  "filePath": "api-examples.md",
  "lastUpdated": 1746015707000
}

Page Frontmatter

{
  "outline": "deep"
}

More

Check out the documentation for the full list of runtime APIs.