Reusing content
Doctave supports a component engine which allows you to reuse content across your project.
Including components in a page
Components live under the _components
directory, which should be located in the project root.
Components should have a .md
extension, just like other Markdown files. The file name is translate to uppercase, for example _components/some-example.md
-> Component.SomeExample
.
<Component.Example />
To include this component in your page, you use the following syntax:
These are my favorite fruits
<Component.Example />
You should now see the content show up:
These are my favorite fruits
Tomato, pineapple, orange and pear.
Adding variables to components
You can add attributes to your components to create more reusable content. To access variables, use the @
symbol, for example @name
.
---
attributes:
- title: name
required: true
---
Hello, {@name}!
To include this component and add a name, you can use the following syntax:
Oh, it's Eve.
<Component.ExampleWithVariable name="Eve" />
This will produce:
Oh, it's Eve.
Hello, Eve
Adding validation to components
To make the reuse of components more convenient, you can validate any incoming values to the attributes.
---
attributes:
- title: name
required: true
validation:
is_a: text
is_one_of:
- Eve
- Tom
---
{@name}
In this example, only the values "Eve" and "Tom" are accepted. Any other values will generate errors.