question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Assign layout to multiple documents by targetting paths/collections

See original GitHub issue

With a lot of similar content (e.g. blog posts), it would be nice to assign a layout to them at one swoop.

Let’s say I have a bunch of documents in src/posts. Then, I would like to somehow target these documents via their common path (could be relative to dir.input, e.g. posts).

An obvious approach would be introducing a new configuration option.

Additionally, would a zero-configuration scenario somehow work? For the documents in src/posts, Eleventy could guess that the default layout for posts is required. If there is one (maybe in _includes/layouts/posts.html), use it; otherwise, continue as usual.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

7reactions
kleinfreundcommented, Mar 14, 2018

With this, how does one apply a layout globally? For example, I have a test.html inside dir.input with no front matter. How can I apply _includes/layouts/default.njk to all templates by default?

Preferably, I wouldn’t need adding any front matter to my content files. Ideally, I would have a directory with dumb content files (e.g. markdown, html) that are processed as templates without having any additional meta data themselves. That would be wonderful.

3reactions
jevetscommented, Aug 16, 2018

I like @zachleat’s eleventyConfig.addData() idea above. This could solve the default layout problem I’ve been facing as well (end up creating many .json files in root that do nothing more than define a layout).

I like @kleinfreund’s idea above, too. It reminds me of how harp.js handles JSON data. A global root-level harp.json file worked well for defaults and other globals, while local _data.json files worked great for overriding and additional data. Specific files can be targeted by keying its basename in the JSON.

The main problem seems to be more specific to root-level templates; the directory/template specific data works well (i.e. posts/posts.json), but it currently doesn’t apply to root-level templates.

A simple _data.json (or _data/_data.json) would be nice, which would basically do the same as the eleventyConfig.addData() idea above. Be nice if I could do either.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Layout - Foundations - Human Interface Guidelines - Design
A layout guide defines a rectangular region that helps you position, align, and space your content on the screen. The system includes predefined...
Read more >
bids.layout.layout — PyBIDS 0.15.5 documentation
This provides a convenient way to restrict file indexing to only those files defined in the "core" BIDS spec, as setting validate=True will...
Read more >
Target Path: Selecting All Nested Collections - SAP Help Portal
A new target path option is now available in the Property Browser that allows for the selection of all objects in all instances...
Read more >
Understanding and configuring the publishing page ...
Name: contains the name of your page layout. · AlsoAppliesTo: when this mapping will be used for multiple page layouts then you can...
Read more >
Layouts and Rendering in Rails - Ruby on Rails Guides
How to create layouts with multiple content sections. ... And the following in your routes file: ... Rails can render a raw file...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found