Giter Site home page Giter Site logo

References between content files about enduro HOT 1 OPEN

gottwik avatar gottwik commented on July 23, 2024
References between content files

from enduro.

Comments (1)

Gottwik avatar Gottwik commented on July 23, 2024

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 enduro.api.flat.load('<path-to-your-file>') to fetch the context.

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.

from enduro.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.