Conditional content

Components•5 min read|
|

wc-if includes or removes content at build time. Content that does not match never reaches the page HTML, the search index or the generated Markdown and llms.txt output, so there is nothing to hide with CSS and nothing for a crawler to find by accident.

Show content to agents or to people

The for attribute picks an audience:

  • for="agents" appears only in the generated Markdown that AI agents read. It is hidden on the web.
  • for="humans" appears only on the web page, and is dropped from the agent Markdown.
<wc-if for="agents"> Machine-readable hint: the API base URL is `https://api.example.com/v2`. Authenticate with a bearer token in the `Authorization` header. </wc-if> <wc-if for="humans"> <wc-button href="/0.3/https://example.com/signup">Get an API key</wc-button> </wc-if>

Use for="agents" for context that helps a model but would clutter the page, such as exact identifiers, constraints and a reminder of the safe order of operations. Use for="humans" for interactive pieces that mean nothing in plain Markdown, such as a button, a tooltip or a video.

This page shows the effect. The next sentence exists only in the agent Markdown: open the Markdown version of this page to read it.

Agent Markdown is what .md URLs, llms-full.txt, Accept: text/markdown requests and the MCP server return. See Reading docs as an agent.

Replace a whole page for agents

To give agents a different page, not just a different block, add docs/<id>.agent.md next to docs/<id>.md. The .agent.md body replaces the page body in everything agents read: dist/<id>.md, llms-full.txt, and so the MCP servers and content negotiation. The web page and the site search index keep the normal page.

docs/ api/ overview.md # what readers see overview.agent.md # what agents read

Use wc-if for="agents" when a page is mostly the same for both audiences and you need a few extra lines. Use an .agent.md file when the page depends on layout, tabs or interactive components that mean little in plain Markdown, and a tighter rewrite serves agents better.

An agent rendition follows these rules:

  • The body is used as written. Variables such as {{VAR}}, wc-* components and includes aren't processed.
  • Its own frontmatter is dropped. The page's frontmatter handling still applies, including agents.markdownFrontmatter.
  • A file over 1 MiB is ignored with a build warning.
  • It isn't a page. It never appears in an automatic sidebar, doesn't count as an orphan page and isn't linted.
  • For a locale, put it in docs.<locale>/<id>.agent.md. A page that falls back to the default language uses the default docs/<id>.agent.md.
  • In a versioned site, each version reads the file from its own branch. Changing only the .agent.md file rebuilds that page.

docslit validate warns with agent-rendition-orphaned when an .agent.md file has no matching <id>.md.

Other conditions

You can combine conditions on one element. All of them must hold.

Attribute Condition
version The build is for one of the listed versions (a comma-separated list), for versioned docs
locale The page is in one of the listed locales. The default locale is en. See Internationalization
attr The named variable from attributes is set and not empty, false or 0
equals With attr: the variable equals one of the listed values
not-equals With attr: the variable equals none of the listed values
not Invert the version, locale or attr condition
for humans or agents

By version

<wc-if version="2.0, 2.1"> This option was added in version 2.0. </wc-if>

By variable

Define a variable in docslit.json, then branch on it. This is a clean way to build a self-hosted and a cloud edition from the same pages:

{ "attributes": { "EDITION": "cloud" } } <wc-if attr="EDITION" equals="cloud"> Sign in at the dashboard to manage your keys. </wc-if> <wc-if attr="EDITION" not-equals="cloud"> Set the `API_KEY` environment variable before you start the server. </wc-if>

By locale

<wc-if locale="fr"> Cette option n'est disponible que dans la documentation française. </wc-if> The audience: humans (web page only) or agents (agent Markdown only). Comma-separated versions. True when the build is for one of them. Comma-separated locales. True for pages under docs.<locale>/. The default locale is en. The name of a variable from docslit.json attributes or page frontmatter. Alone, it is true when the variable is set and not empty, false or 0. With attr: comma-separated values that the variable must equal. With attr: values that the variable must not equal. Invert the version, locale or attr condition.

Rules

  • Leave a blank line after the opening tag and before the closing tag when the content is block Markdown, such as a list or a code fence.
  • Evaluation happens before the page is rendered, so content inside a wc-if can use variables, includes and any other component.
  • Only matching content is searchable and visible to agents, so do not put anything in a non-matching branch that must stay secret. It never reaches the output of that build, but it is in your source.

Migrating from Mintlify or Fern

The importer converts the conditional components of both platforms:

Platform Source DocsLit
Mintlify <Visibility for="agents"> and for="humans" <wc-if for="agents"> and for="humans"
Fern <llms-only> and <llms-ignore> <wc-if for="agents"> and for="humans"
Fern <If versions={["v1"]}> <wc-if version="v1">

Content gated by login, roles or groups cannot exist on a static site, so the importer removes it and reports it. See the component mapping.

Next steps