Set custom page variables?


#1

Is there any way to set custom page variables in stackedit? The use case is that I want to add specific body tag classes to different files upon publication.

Here’s my attempt that didn’t work:

within File Properties > YAML Properties:

body-class: post
extensions:
  preset: ‘’

And within the the Stackedit template:

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

I also tried this in the Stackedit template:

<body class=“stackedit {{page.body-class}} test”>
{{{files.0.content.html}}}
<body>

But the body-class didn’t appear in stackedit’s html output.


#2

Right, I should have mentioned this in my other post, especially considering I was initially confused by the same thing.

All YAML properties are accessible under files.0.content.properties, both “standard” ones like extensions, and arbitrary custom ones like body-class.

So your example should look something more like this:

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

Yeesh, that’s a lot to type. Ah well.


#3

Thanks, I’ll try that.

I searched for YAML documentation on this and couldn’t find anything. The standard stackedit html template uses <title>{{files.0.name}}</title> so I figured custom properties would be at the same level in the hierarchy, but I guess .name is literally the file name rather than a property defined within it.

There’s probably lots of stuff I could do with stackedit that I’ll never know about because the documentation is so limited.