-
-
Notifications
You must be signed in to change notification settings - Fork 495
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dashes in global data variable names #567
Comments
Hmm as a short term solution I did find a way to do this in Nunjucks. It’s related to this mozilla/nunjucks#833 Just using What other engines are you using? Gonna leave this open because it needs more work, but I’ll attach those test cases for Liquid and Nunjucks. |
Here’s the filter for a workaround in Nunjucks: e7cd430#diff-51893acfe86995eb32c931a0dbca7842R113 |
If you want even more, you can return the current context (which I usually pipe to a debug filter). // Returns current context - useful for debugging
exports.getContext = function() {
return this.ctx;
} |
Huh, so it does! Think I got distracted by a.) using Nunjucks on a different project where I believe you can’t use |
Going to go ahead and close this as it seems like an edge case to me, but just for future searchers here is the workaround in Nunjucks to reference a global variable with dashes in the variable name.
and then in your Nunjucks template:
|
I've run into this where I have a data file named
I realise I could rename the file to |
@michrome can you open a new issue, please? |
I think a better way forward that what was documented here will be #1919 |
Given the following frontmatter:
I can access the first value within a collection loop using the
item.data.fruit
variable, and on pages by usingfruit
.For the second value, given its hyphenated nature, I’ll need to use the bracket notation. Within a collection loop I can access it using
item.data['is-it-tasty']
, but how can I access this value on a page? I triedpage.data['is-it-tasty']
, but that didn’t work, nor diddata['is-it-tasty']
. What’s the expected approach?(Side note: the apparent discrepancy between
item.data.thing
within loops, and justthing
on pages keeps tripping me up 🙃.)The text was updated successfully, but these errors were encountered: