Say I'm building a blog with DocPad that has a listing document and a bunch of posts (in a filtered collection). The listing displays the beginning of the content of each post using document.contentRenderedWithoutLayouts
. (How?) Does DocPad make sure all the posts are rendered before rendering the listing?
A quick debug run with docpad -d --env static run
suggests the listing is rendered every time a new post is rendered. Is that about right?
What if there's a cycle? Say one of the posts wants the listing's contentRenderedWithoutLayout
?
:) this is where DocPad gets super smart :)
Whenever you do a template helper call to fetch a document that isn't your own, we take note of that and set the referencesOthers
meta data property to true. We then proceed to render all of the documents that don't reference others first, then render all those that do reference others.
This is also why when you modify a layout, we will regenerate all the documents that use it. As well as when you modify a blog post, we'll also regenerate any listings of that blog post.
If you have circular references, we will notify you of that such an occurrence has occurred and recommend that you increase the renderPasses
configuration property to ensure that it renders enough times to be useful.
The exact code behind the render passes is here: https://github.com/bevry/docpad/blob/v6.32.0/src/lib/docpad.coffee#L2567-L2579