4b6817381b
CI (OpenClaw E2E) / openclaw test (push) Has been cancelled
CI / coverage-report (push) Has been cancelled
CI / test-kubernetes (push) Has been cancelled
CI / should-run-thorough (push) Has been cancelled
CI / test-thorough (cloudwatch-demo) (push) Has been cancelled
CI / test-thorough (flink-ecs) (push) Has been cancelled
CI / test-thorough (upstream-lambda) (push) Has been cancelled
CI / test-thorough (prefect-ecs-fargate) (push) Has been cancelled
Release / build-binaries (zip, opensre.exe, onefile, windows-latest, windows-x64) (push) Has been cancelled
Benchmark image — build + push to ECR (any adapter) / build + push (push) Has been cancelled
CI / quality (ubuntu-latest) (push) Has been cancelled
CI / test (tools-runtime) (push) Has been cancelled
CI / test (e2e-general) (push) Has been cancelled
CI / test (cli-runtime) (push) Has been cancelled
CI / test (e2e-provider-and-openclaw) (push) Has been cancelled
CI / test (integrations-and-misc) (push) Has been cancelled
Release / verify (push) Has been cancelled
Release / build-python-dist (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, macos-15-intel, darwin-x64) (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, macos-latest, darwin-arm64) (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04, linux-x64) (push) Has been cancelled
Release / publish-release (push) Has been cancelled
Release / publish-main-release (push) Has been cancelled
Interactive Shell Live (PR + post-merge) / turn-checks (no-LLM) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
Interactive Shell Live (PR + post-merge) / turn-live shard ${{ matrix.shard_index }} (push) Has been cancelled
Release / prepare (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04-arm, linux-arm64) (push) Has been cancelled
Synthetic Deterministic Tests / Synthetic offline (deterministic) (push) Has been cancelled
111 lines
2.5 KiB
Plaintext
111 lines
2.5 KiB
Plaintext
---
|
|
title: "Reusable snippets"
|
|
description: "Reusable, custom snippets to keep content in sync"
|
|
icon: "recycle"
|
|
---
|
|
|
|
import SnippetIntro from '/snippets/snippet-intro.mdx';
|
|
|
|
<SnippetIntro />
|
|
|
|
## Creating a custom snippet
|
|
|
|
**Pre-condition**: You must create your snippet file in the `snippets` directory.
|
|
|
|
<Note>
|
|
Any page in the `snippets` directory will be treated as a snippet and will not
|
|
be rendered into a standalone page. If you want to create a standalone page
|
|
from the snippet, import the snippet into another file and call it as a
|
|
component.
|
|
</Note>
|
|
|
|
### Default export
|
|
|
|
1. Add content to your snippet file that you want to re-use across multiple
|
|
locations. Optionally, you can add variables that can be filled in via props
|
|
when you import the snippet.
|
|
|
|
```mdx snippets/my-snippet.mdx
|
|
Hello world! This is my content I want to reuse across pages. My keyword of the
|
|
day is {word}.
|
|
```
|
|
|
|
<Warning>
|
|
The content that you want to reuse must be inside the `snippets` directory in
|
|
order for the import to work.
|
|
</Warning>
|
|
|
|
2. Import the snippet into your destination file.
|
|
|
|
```mdx destination-file.mdx
|
|
---
|
|
title: My title
|
|
description: My Description
|
|
---
|
|
|
|
import MySnippet from '/snippets/path/to/my-snippet.mdx';
|
|
|
|
## Header
|
|
|
|
Lorem ipsum dolor sit amet.
|
|
|
|
<MySnippet word="bananas" />
|
|
```
|
|
|
|
### Reusable variables
|
|
|
|
1. Export a variable from your snippet file:
|
|
|
|
```mdx snippets/path/to/custom-variables.mdx
|
|
export const myName = 'my name';
|
|
|
|
export const myObject = { fruit: 'strawberries' };
|
|
```
|
|
|
|
2. Import the snippet from your destination file and use the variable:
|
|
|
|
```mdx destination-file.mdx
|
|
---
|
|
title: My title
|
|
description: My Description
|
|
---
|
|
|
|
import { myName, myObject } from '/snippets/path/to/custom-variables.mdx';
|
|
|
|
Hello, my name is {myName} and I like {myObject.fruit}.
|
|
```
|
|
|
|
### Reusable components
|
|
|
|
1. Inside your snippet file, create a component that takes in props by exporting
|
|
your component in the form of an arrow function.
|
|
|
|
```mdx snippets/custom-component.mdx
|
|
export const MyComponent = ({ title }) => (
|
|
<div>
|
|
<h1>{title}</h1>
|
|
<p>... snippet content ...</p>
|
|
</div>
|
|
);
|
|
```
|
|
|
|
<Warning>
|
|
MDX does not compile inside the body of an arrow function. Stick to HTML
|
|
syntax when you can or use a default export if you need to use MDX.
|
|
</Warning>
|
|
|
|
2. Import the snippet into your destination file and pass in the props
|
|
|
|
```mdx destination-file.mdx
|
|
---
|
|
title: My title
|
|
description: My Description
|
|
---
|
|
|
|
import { MyComponent } from '/snippets/custom-component.mdx';
|
|
|
|
Lorem ipsum dolor sit amet.
|
|
|
|
<MyComponent title={'Custom title'} />
|
|
```
|