Can I use front matter in Stackedit markdown files?


#1

I’d like to use front matter in Stackedit markdown files so that I can set custom variables to use in Stackedit’s handlebar template. The use case is that I want to add specific classes to different files upon publication.

Here’s my test stackedit markdown file:

---
body-class: post
---
test demo content

Here’s my stackedit template:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>{{files.0.name}}</title>
</head>

<body class="stackedit {{files.0.body-class}} test">
  {{{files.0.content.html}}}
</body>
</html>

Here’s the resulting html output that stackedit publishes:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>front-matter-test</title>
</head>

<body class="stackedit  test">
  <hr>
<h2 id="body-class-post">body-class: post</h2>
<p>test demo contents</p>

</body>
</html>

Is there anything I do to make stackedit recognize the front matter?


#2

Do you just want to add “custom variables” to your files in general,
or do you specifically want to write front matter in the file itself?

If you don’t need the properties to be in the prose, you can open the StackEdit Menu in the top right, and click File Properties.

If you feel any custom variables you add must be in the markdown itself, frontmatter style, I’m afraid you’re in for a world of pain! (jk… mostly)
At that point you’ll have to fiddle with writing Handlebars helpers…

If it is the latter, and you want any help with that, just let me know.