-
-
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
Access page
data in shortcodes without arguments
#741
Comments
Personally, I go with a partial + global |
yeah in this case I have YAML from my pages that I want to use as well. For example, I may give each page a But maybe doing an include or macro is a better option because it will have access to all of the current page data. I prefer writing in JavaScript as opposed to Nunjucks for anything requiring logic so that's why I was leaning toward a Shortcode. |
Fair enough. |
I have also a use case in a plugin where I would like Eleventy to pass the page data to a shortcode, without requiring the user to put More precisely, I'm working on improvements for @eeeps 's respimg plugin for responsive images. I like to store images alongside the Markdown file they're used in, and make the build copy them alongside the generated HTML (like I explained in my Other page data could be useful too, so having it all would be great. I'm using Nunjucks, I hope it one of the languages for which it is possible: https://twitter.com/eleven_ty/status/1196112060809195524 |
I also have the same use case as @nhoizey and created custom tags to help with this: |
@robdodson great, I'll look at your code, thanks for sharing! |
I found a better solution with transforms for my use case, but they don't have any context either… 😅 See #789 |
This will ship with 0.11.0. Docs issued at #1044 |
If you saw this last night, I modified the behavior to only expose |
page
data in shortcodes without arguments
Follow along with work to analyze and normalize |
@zachleat do you have an example of how this would work? I tried the following with 0.11 beta-2: module.exports = (content) => {
console.log(this.page); // undefined
}; |
Ah sorry @robdodson it’ll be in beta 3. Just coded it yesterday |
@zachleat Question, I'm using Handlebars. I have a shortcode that takes a set of parameters to build a url. I use rest parameter in my function there |
Here you mention why we don't include the |
Same question as @adamduncan. Also posted this question on Stack Overflow maybe it gets some more visibility. Also opened #1591 Q&A for exactly this question. |
I was thinking of turning all of my meta tags into a Meta shortcode.
Currently my template looks like this:
Is there a way for me to pass a single data object to my shortcode which would contain
title
anddescription
, similar to how you can dowith context
on a macro? Or do I have to pass these values individually. Because each child page might set a lot of values in their YAML, it feels like a lot to pass each property to the shortcode.The text was updated successfully, but these errors were encountered: