Skip to content

Variable

Jacob Chirayil edited this page Feb 13, 2019 · 2 revisions

Variable Support

Use case 1 - variables are declared as part of the .md file

Advantage - variables declared as part of yaml and can be referenced multiple time within the document.

file: file1.md

---
title: File1
user1: John Smith
user2: Jane Smith
---
File with variable.
The two authorized users are {#var user1} and {#var user2}. The primary user - {#var user1} - can enable/disable the account of {#var user2}.

output: file1.html

<p>File with variable.</p>
<p>The two authorized users are John Smith and Jane Smith. The primary user - John Smith - can enable/disable the account of Jane Smith.</p>

Use case 2 - variables are declared as part of config

Advantage - variables can be shared between multiple files

config setting

...
var varreplace = require('metalsmith-var-replace');
...
    .use(varreplace({
        actions:[{
            type:'var',
            varValues: {
                'adminuser':'John Smith',
                'fruit':'apple'
            }
        }]
    })
...

file: file1.md

---
title: File1
---
File with variable (values defined about config level).
The name of the administrator is {#var adminuser} and his/her favorite fruit is {#var user2}.

output: file1.html

<p>File with variable (values defined about config level).</p>
<p>The name of the administrator is John Smith and his/her favorite fruit is apple.</p>
Clone this wiki locally