Closed
Description
Problem
It's not currently possible to have a conditional that checks whether a key is set in the locals
object.
This is an expansion to #79
Details
I have a use case where the contents of the locals
object is dynamic. It's read from front-matter from a markdown file.
I would like to be able to check whether the key is set in the locals object and then output the value if it does.
Front matter:
---
skeleton: base.html
title: My First Post
category: 'Cool category'
---
Which is parsed into the following object:
{
skeleton: 'base.html',
title: 'My First Post',
category: 'Cool category',
}
If I for example don't include category
in the front-matter then the object would look like the following:
{
skeleton: 'base.html',
title: 'My First Post',
}
In the HTML template it's not currently possible to check whether category
exists:
<if condition="category">
<p>In: {{ category }}</p>
</if>
It throws the following error:
UnhandledPromiseRejectionWarning: ReferenceError: category is not defined
I've tried the following as well:
<if condition="{{ category }}">
<p>In: {{ category }}</p>
</if>
Which throws the same error as in #101
Error Logs
The full error:
(node:99739) UnhandledPromiseRejectionWarning: ReferenceError: category is not defined
(node:99739) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
Metadata
Assignees
Labels
No labels