Skip to content

Support for merging a layouts fileMeta with the current documents during layout rendering.#133

Closed
mmoulton wants to merge 1 commit into
docpad:masterfrom
mmoulton:master
Closed

Support for merging a layouts fileMeta with the current documents during layout rendering.#133
mmoulton wants to merge 1 commit into
docpad:masterfrom
mmoulton:master

Conversation

@mmoulton

Copy link
Copy Markdown

Now when a property of the same name is defined both in the document and the layout, the documents value is preferred, if it exists. If the property exists in the layout, but not the document, the layouts value will be used. Enabling sane defaults to be defined in the layout and overridden in the document.

…cuments rendering in the absence of an equivalent key in a documents metadata
@balupton

Copy link
Copy Markdown
Member

What an interesting idea! Never thought of that! Thanks!

Happy to do a pull in the next release, although this does seem like it could introduce a few regressions... Perhaps, if I introduce it as a new property called fileMetaMerged would that still work for you?

@Delapouite

Copy link
Copy Markdown
Contributor

Great mmoulton, that's a really useful concept.
I had to use double negative variables in documents meta to emulate this kind of default variables in templates.

@balupton

Copy link
Copy Markdown
Member

Two things to get this merged:

  1. Could this change bring about any counter-intuitive side-effects, or break any existing code?
  2. We will need tests for this.

One use case I think with point 1, is that if we have title: 'My document' inside our document, then title: 'Untitled' inside our layout, I feel that would be a common use case. I feel that the document data should take preference over the layout data. Would you agree? Is there a particular reason it was coded in the vice versa?

Thanks mate, it is a fantastic change and I would love to see it included.

@mmoulton

Copy link
Copy Markdown
Author

I never got around to cleaning up this pull.

In response to the two issues:

  1. Assuming it works as you described where title: 'My Document' inside a document overrides title: 'Default Title' in the layout, then I do not see any regression issues. - As you noted, this is inverses, and will be fixed.
  2. I will be happy to write test for this.

I will close this pull request and start a new one off the current master with test cases soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants