-
Notifications
You must be signed in to change notification settings - Fork 29
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
Dynamic output from one template #16
Comments
Hey Paul, Could you create a PR with a failing test that shows what you are expecting, and I will get it working for you :] |
Sure! I'll look at this this weekend. Thanks |
Thank you On Thursday, May 8, 2014, Paul Wright [email protected] wrote:
patrick |
ping @paintedbicycle |
My bad. On it. |
ain't no thang :D |
Ok I have added a failing test. Take a look and see if you think the idea matches your script. No worries if not. Happy to talk through it more as well, especially when it comes to setup. Might be a better way to dynamically pass all children, etc. |
Was there a solution for this? |
I'm trying to get this working as well. Did you guys ever make any headway? |
Sorry guys, I have been swamped at work. I would like to get this in asap, however. Thought on this a bit, however, and I have a proposal I would love to run by the three of you Basically, I think it makes the most sense to use handlebars templates on the filenames themselves, and then just process the file as we normally do.
The only issue I am hitting is that the task looks over templates, and since there is only one in this setup, I am not sure when to properly loop over the templateData to create the output files. Unless anyone has a problem with this, or a better idea, this is what I will be moving forward with |
Swamped here too! :) I wound up hacking up a solution. I'll see if I can get a PR together that works without some of the more questionable tactics I used. |
thanks @Sneagan! |
Happy to hear there is some interest in this! The original idea was this:
So, in the data file, you'd have:
Pretty standard format, but most grunt templating scripts I've worked with don't quite go that distance. Anyway, that's where my original thoughts were. Paul |
Thanks for the added clarity, Paul! |
@paintedbicycle - correct me if I am wrong, but the only real thing stopping you from doing that is the output naming, right? Like, if you manually added every post in your config, it would work, just be horrible, ugly, slow and awful - right? |
Yes, making each file separately would be possible, but a pain. Would be great to be able to loop through any number of "posts" in the json file. Also, I'm not sure currently how I'd create a page from one part of the data file and then pull excerpts from a number of other pages onto that page as in the blog list option. |
Sorry, I don't think my question was clear. The only thing that is preventing it is the file naming, correct? If that is the case, did you see my proposal on how to do that? |
ping @paintedbicycle |
I think your proposal covers it - just having a hard time visualizing it. I see that the output file is dynamic, so it seems that you could have multiple "events" in the data.json file and it would loop through them. As long as you could do other things like including a header and footer and access other parts of the data file (for global things like site title) then I think we'd be set |
I guess the closest example is your globbed examples with the dynamic filename, however I don't want to have separate JSON and separate input files. I'd like to loop through the JSON, using one input template and output multiple output templates with a name that comes from the JSON. So a foreach loop, going through the JSON and creating dynamic outputs with names I can control from the data. Additionally, I'd like to be able to specify a "section" in the JSON during the build call (gruntfile.js) that makes the data start from that section. This would be helpful for the above - I could loop though the "posts" array, or the "events" array in the JSON file. And it would be nice if the PRE and POST could use JSON data too, but that doesn't seem to be the case. I'd throw a header in there with page title, that I could get from the JSON. |
I'm looking for a way to have one of each type of content in my /src/ folder, but perhaps multiple versions in the /dist/ folder. Types could be 'events', 'blog posts', 'people', etc. I only need one version of the template for each of these and the .json file(s) would have the content.
Something like:
Where above, there is one event template and perhaps multiple .json files (one per event). But I would need a way to change the output title based on something in the .json file.
Ultimately, I'd prefer to only have one global .json file and then do something like event.eventName but there doesn't seem like a way to output multiple different files based on one template and json file. I thought about declaring each block separately in the gruntfile, but with one template and one json file, there is no way to tell the processor which block to read from the .json file.
Are either of these two approaches possible?
Paul
The text was updated successfully, but these errors were encountered: