-
Notifications
You must be signed in to change notification settings - Fork 120
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
References between content files #46
Comments
Thank you for a very good question, @dotloadmovie . I am glad you like enduro.js, I hope we can improve it together. Yea, this can't be currently done easily, but I wish it was because it's a good idea ;-) I created a sample for you: https://github.com/Gottwik/enduro_samples/tree/master/related_articles The idea is to load the related articles using a custom handlebars helper. Veeery simple. Basically you just use The template looks like this: <h1>{{name}}</h1>
<p>{{text}}</p>
<h3>related articles:</h3>
<ul>
{{#related_articles}}
<li>{{name}}</li>
{{/related_articles}}
</ul> and the helper looks like this: var Promise = require('bluebird')
enduro.templating_engine.registerHelper('related_articles', function (options) {
// store the actual rendered html
// alternativelly a each helper could be used
var rendered_html = ''
// store the promises to read related articles
var related_article_promises = []
// go throgh all relate articles and load them
for (index in this.related_articles) {
// store the related article
var related_article = this.related_articles[index]
// load the actual content of the article
var related_article_promise = enduro.api.flat.load('/generators/article/' + related_article.related_article_id)
.then((related_article_context) => {
// generate the actual html code
return options.fn(related_article_context)
})
.then((rendered_html_block) => {
// add the html code together with the previous ones
rendered_html += rendered_html_block
})
// add whole thing to a array of promises
related_article_promises.push(related_article_promise)
}
// return whole html block upon reading all related articles
return Promise.all(related_article_promises)
.then(() => {
return rendered_html
})
}) Eeeh, it looks complicated, but it isn't, I promise! Btw, the circular thing could be solved by a shallow globalizer: http://www.endurojs.com/docs/globalizer#shallow-globalizer Let me know if this helps you, or if you had any other ideas on how to solve this. |
Hi @Gottwik - really loving this project, great work. I'm using it to build a simple static blog and it's working great, however I was looking for some guidance on a question that's arisen
For each post I add I'd like to have a sections of "related content" at the bottom of the page. To avoid duplication of content ideally I'd be able to reference other content files inside the same generator - something like
Currently I can access global items but not siblings. Is there any way you recommend of doing this? (I see potential issues with circular references of course...)
The text was updated successfully, but these errors were encountered: