The DlRenderer inline component lets you render custom, sharable Markdown components anywhere in your content. It takes care of managing their special location, caching, and automatic property extension.
Features
- š rendering sharable Markdown components
- š property-based Markdown formatting
- š”ļø safe path resolution with error handling
- ā” dynamic data injection with
dl.inDocDataintegration - šļø smart content caching
Usage
Below you'll find a step-by-step guide on how to create and use custom and shareable Markdown components. These are one of the best ways to avoid repetition and improve your content management workflow.
Create a new shareable Markdown component
Inside the special content/_shared folder, create a new Markdown component. You can add any type of content there - whether itās plain text, another content component (your own custom one), or a built-in DocLayer component.
_shared folder is a different one
The content/_shared folder is not treated as a regular content collection "bucket" - items placed there wonāt appear in your navigation or be rendered as content. Instead, these Markdown components will only be shown when using the DlRenderer component. These files are treated as a data ones, each with a special data object defined by its schema.
Render a new shared Markdown component
Once youāve created a new sharable Markdown component - let's say, shared-component.md - you can display it in your content using the DlRenderer. Simply reference the file name as the unique key within the default slot, like this:
Component name validation
The name of the component will be validated by Markdownlint. After you create a new shared component, you may see a warning that the file does not exist yet. This is normal, since the component hasn't been registered, DocLayer will not detect it immediately. To register your new component, simply restart your application so DocLayer can rebuild the shared components registry. This mechanism helps avoid unnecessary recalculation while creating new content files and improves rendering performance.
You can organize components into subfolders within the _shared directory. DlRenderer will automatically recognize the correct path, resolving appropriately. It will also check whether the specified file exists, and if not, a dedicated error will be shown.
Most of the time, DlRenderer will be used as a standalone component (defined within the new line), written as :dl-renderer[...], which works mentally as a block element. Since there is no need to close anything inside the block notation this component is defined exactly like an inline one. However, if you need to use a real inline component - for example, a small snippet within a sentence or a tooltip - be sure to use the inline prop. This will make the component fit naturally within your text flow.
Hereās how you use it:
With dynamic data
DlRenderer is able (using the $doc handler) to dynamically pass primitive data to sharable Markdown components. Let's cover this capability with a dedicated example.
So you've created the shared-component.md, inside which you want to define reusable DlCallout component, something like this:
To render this component, simply use :dl-renderer[shared-component] wherever you want it to appear in your content. Great. But what if you want to pass dynamic data to it? You can easily do this using the :data prop, passing an object with your desired data. Like this:
What's more, thanks to the capabilities of DlWrapper, you can overwrite the props of any content component used within your shared component by passing dynamic data. For example, you might want to change the title or type of a DlCallout. To do this just use the special #props slot. Like this:
OK, a bit of magic - the DlWrapper, which handles advanced actions for components like DlCallout - uses a special, dedicated composable called usePropsExtender. This composable reads the #props slot allowing to override properties for your shared component. The updated values are then provided to the component via the special data binding $doc handler, which is accessible inside all of the Markdown components.
You don't need to nest the data for your properties - they are resolved automatically. Also, because this data is handled with the useInDocData composable, any data from the inDocData object will also be available.
As shown above, you're not limited to overriding only properties - if you want to pass other data to your shared component, simply include them in the data prop and access them using the $doc handler.
Why to use built-in property extending?
You might ask why this approach is better than simply passing regular dynamic properties to your content components?
- First, itās not limited to local data - you can provide data from parent components as well as from the global registry, managed by the
dl.inDocDataobject. - Second, dynamic property binding with the
$dochandler isnāt possible when using regular dynamic props, since those values are resolved as static data, which can make data binding inconsistent. - Third, you can mix static and dynamic content for the same property.
- Finally, with this approach, data binding happens at the component level, is cached, and reused for future renders, rather than being resolved each time during Markdown parsing.
Use only primitives
Please note that the properties you wish to override must be of primitive type: either a string, number, or boolean. This restriction helps prevent accidentally sharing complex or nested objects across the whole application, which may lead to performance issues. For most use cases, primitives are sufficient.
Markdown parsing
Since bound data is always passed as a string, Markdown syntax/tags will not be recognized and will be displayed as written. DlRenderer can parse basic Markdown notations like bolds, inline code, and italics if you enable the parse prop. This mechanism is disabled by default, as traversing through the entire structure may impact performance. It is always recommended to keep data objects small and limited to primitive values.
As the AST renderer
If you need to render the AST directly in your Vue components, you can use the special body prop (of type MinimarkNodes | ComarkNodes). This prop is intended for use with AST input only, and should not be used together with regular Markdown content. When you pass an AST to the body prop, the renderer will output the final HTML markup. To prepare the AST, you can use the utilMDtoHAST utility.
Props
Here are the properties you can use with the DlRenderer component. Each property should be set on an individual component instance; they do not affect the global configuration. More about defining properties in MDC components you can read here.
| name | type | default | description |
|---|---|---|---|
data | object | undefined | Data to pass to the rendered component. These should only contain primitive values. |
inline | boolean | undefined | Renders the component as inline, useful for displaying inline text boxes or tooltips. |
parse | boolean | undefined | Performs Markdown parsing for data bindings. |
route prop is deprecated
Please don't use the route property anymore as it being deprecated, use the default slot instead. It's still available for internal use, however, using it can lead to unexpected behavior and performance issues.
Slots
| name | description |
|---|---|
default | The shared component name to be resolved, validated by the |
Caching
The resolved data of shared components is automatically cached, further used on subsequent renders. This means that shared and reusable chunks of your content are efficiently handled, being fetched from the collection only once.
We are working on a fully rendered markup smart caching, which will be available in future releases - stay tuned.
