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

Option for "layout: default" in _config.yml #453

Closed
pdurbin opened this Issue Dec 15, 2011 · 26 comments

Comments

Projects
None yet
@pdurbin

pdurbin commented Dec 15, 2011

For some of my Jekyll sites I'm always using the same layout for all my pages and posts. It would be nice to be able to specify "layout: default" once in my _config.yml and have that layout applied to any file with YAML Front Matter that doesn't have any layout specified explicitly.

I asked a related question on Stack Overflow and answered it with a plugin that seems to work (i.e. I don't have to write "default: layout" over and over) but I'm no Rubyist and it doesn't handle the _config.yml part. I called it _plugins/implicit-layout.rb:

http://stackoverflow.com/questions/8490528/how-can-i-make-jekyll-use-a-layout-without-specifying-it

@mytharcher

This comment has been minimized.

Show comment
Hide comment
@mytharcher

mytharcher Jan 15, 2012

Em, it may be very useful in some cases like yours, but think another case:

If you have some pages just want to be parsed and copy to the right place, and you set the default layout, than these pages you don't want to be wrapped into any layout will be wrapped into the default.

The resolution of this should add anthoer specail layout called layout: NONE or some keyword else, in order to avoid a page be wrapped into any layouts.

mytharcher commented Jan 15, 2012

Em, it may be very useful in some cases like yours, but think another case:

If you have some pages just want to be parsed and copy to the right place, and you set the default layout, than these pages you don't want to be wrapped into any layout will be wrapped into the default.

The resolution of this should add anthoer specail layout called layout: NONE or some keyword else, in order to avoid a page be wrapped into any layouts.

@trans

This comment has been minimized.

Show comment
Hide comment
@trans

trans Jun 17, 2012

Contributor

I think one can already put layout: ~ without hurting anything. Even if not it would be easy to fix.

Considering the whole point of Jekyll is to create a website/blog site, I'm fairly sure the vast majority of the time a default layout is going to be a desired result. In fact it would be even nicer if pages default to _layouts/page.html and posts to _layouts/post.html. And guess what? If we put only '{{ context }}' in the page.html layout, it would act just like there were no layout, just as it does now.

Contributor

trans commented Jun 17, 2012

I think one can already put layout: ~ without hurting anything. Even if not it would be easy to fix.

Considering the whole point of Jekyll is to create a website/blog site, I'm fairly sure the vast majority of the time a default layout is going to be a desired result. In fact it would be even nicer if pages default to _layouts/page.html and posts to _layouts/post.html. And guess what? If we put only '{{ context }}' in the page.html layout, it would act just like there were no layout, just as it does now.

@kizu

This comment has been minimized.

Show comment
Hide comment
@kizu

kizu Jan 24, 2013

+1 here: it would be nice to have an option to set default layout in _config.yml. And it would be even awesomer if we could set different default layouts based on paths, like you can set different default metadata for different paths in Prose.

And yes, there could be a keyword like nil or something to disable the layout from any given page. But I think that for most of the sites and blogs there with Jekyll there is only one layout used everywhere, so it would be handy and convenient to have such option.

kizu commented Jan 24, 2013

+1 here: it would be nice to have an option to set default layout in _config.yml. And it would be even awesomer if we could set different default layouts based on paths, like you can set different default metadata for different paths in Prose.

And yes, there could be a keyword like nil or something to disable the layout from any given page. But I think that for most of the sites and blogs there with Jekyll there is only one layout used everywhere, so it would be handy and convenient to have such option.

@parkr parkr closed this Mar 19, 2013

@tofumatt

This comment has been minimized.

Show comment
Hide comment
@tofumatt

tofumatt Apr 12, 2013

Why was this issue closed without a comment or commit? This seems like it would be a useful feature to have.

tofumatt commented Apr 12, 2013

Why was this issue closed without a comment or commit? This seems like it would be a useful feature to have.

@parkr

This comment has been minimized.

Show comment
Hide comment
@parkr

parkr Apr 12, 2013

Member

Layouts should not be set globally. They should be set on a per-page and per-post basis.

Right now, the layout defaults to page for Pages and post for Posts. If you'd like to override those, set your layout in the Page or Post YAML Front-Matter.

Member

parkr commented Apr 12, 2013

Layouts should not be set globally. They should be set on a per-page and per-post basis.

Right now, the layout defaults to page for Pages and post for Posts. If you'd like to override those, set your layout in the Page or Post YAML Front-Matter.

@kizu

This comment has been minimized.

Show comment
Hide comment
@kizu

kizu Apr 12, 2013

Layouts should not be set globally. They should be set on a per-page and per-post basis.

Arguments? I can't see why it can't or shouldn't be done.

kizu commented Apr 12, 2013

Layouts should not be set globally. They should be set on a per-page and per-post basis.

Arguments? I can't see why it can't or shouldn't be done.

@parkr

This comment has been minimized.

Show comment
Hide comment
@parkr

parkr Apr 12, 2013

Member

It's not appropriate for the Jekyll core, because the default should always be nil. I almost didn't accept @trans's PR for defaulting to page/post layouts, because it is "automagical." Jekyll's strength is in how straight-forward and basic it is. The more options and complexity we add, the worse off everyone is.

Member

parkr commented Apr 12, 2013

It's not appropriate for the Jekyll core, because the default should always be nil. I almost didn't accept @trans's PR for defaulting to page/post layouts, because it is "automagical." Jekyll's strength is in how straight-forward and basic it is. The more options and complexity we add, the worse off everyone is.

@kizu

This comment has been minimized.

Show comment
Hide comment
@kizu

kizu Apr 12, 2013

default default layout should be nil, yeah. But it should be so it could be changed to something else.

Right now the absence of such feature actually makes things more complex for a lot of people — it's another thing you need to set always in your pages and posts and if you have only one layout, then you need to write redundant stuff for every page.

kizu commented Apr 12, 2013

default default layout should be nil, yeah. But it should be so it could be changed to something else.

Right now the absence of such feature actually makes things more complex for a lot of people — it's another thing you need to set always in your pages and posts and if you have only one layout, then you need to write redundant stuff for every page.

@mattr-

This comment has been minimized.

Show comment
Hide comment
@mattr-

mattr- Apr 12, 2013

Member

I'm in favor of being able to set a site-wide layout in _config.yml with a
hard coded default of nil. I don't think it adds any extra complexity
than the config setting for safe does, for example.

On Fri, Apr 12, 2013 at 9:20 AM, Roman Komarov notifications@github.comwrote:

default default layout should be nil, yeah. But it should be changed to
something else.

Right now the absence of such feature actually makes things more complex
for a lot of people — it's another thing you need to set always in your
pages and posts and if you have only one layout, then you need to write
redundant stuff for every page
.


Reply to this email directly or view it on GitHubhttps://github.com//issues/453#issuecomment-16295412
.

Member

mattr- commented Apr 12, 2013

I'm in favor of being able to set a site-wide layout in _config.yml with a
hard coded default of nil. I don't think it adds any extra complexity
than the config setting for safe does, for example.

On Fri, Apr 12, 2013 at 9:20 AM, Roman Komarov notifications@github.comwrote:

default default layout should be nil, yeah. But it should be changed to
something else.

Right now the absence of such feature actually makes things more complex
for a lot of people — it's another thing you need to set always in your
pages and posts and if you have only one layout, then you need to write
redundant stuff for every page
.


Reply to this email directly or view it on GitHubhttps://github.com//issues/453#issuecomment-16295412
.

@parkr

This comment has been minimized.

Show comment
Hide comment
@parkr

parkr Apr 12, 2013

Member

I still have a terrible feeling about a global layout. Let me ask @mojombo and @qrush their thoughts - I'm sure there was a justification early on.

Member

parkr commented Apr 12, 2013

I still have a terrible feeling about a global layout. Let me ask @mojombo and @qrush their thoughts - I'm sure there was a justification early on.

@parkr

This comment has been minimized.

Show comment
Hide comment
@parkr

parkr Apr 12, 2013

Member

@mattr- It's a third layer to the cascade of layout: page/post-level, page/post default, site default. It's undeniably another layer of complexity.

Member

parkr commented Apr 12, 2013

@mattr- It's a third layer to the cascade of layout: page/post-level, page/post default, site default. It's undeniably another layer of complexity.

@mattr-

This comment has been minimized.

Show comment
Hide comment
@mattr-

mattr- Apr 12, 2013

Member

You're right. I agree it's more complex for us to implement. However, I do
not believe it is more complex for the user to use, which is why I'm still
in favor of having something like this.

On Fri, Apr 12, 2013 at 9:38 AM, Parker Moore notifications@github.comwrote:

@mattr- https://github.com/mattr- It's a third layer to the cascade of
layout: page/post-level, page/post default, site default. It's undeniably
another layer of complexity.


Reply to this email directly or view it on GitHubhttps://github.com//issues/453#issuecomment-16296398
.

Member

mattr- commented Apr 12, 2013

You're right. I agree it's more complex for us to implement. However, I do
not believe it is more complex for the user to use, which is why I'm still
in favor of having something like this.

On Fri, Apr 12, 2013 at 9:38 AM, Parker Moore notifications@github.comwrote:

@mattr- https://github.com/mattr- It's a third layer to the cascade of
layout: page/post-level, page/post default, site default. It's undeniably
another layer of complexity.


Reply to this email directly or view it on GitHubhttps://github.com//issues/453#issuecomment-16296398
.

@maul-esel

This comment has been minimized.

Show comment
Hide comment
@maul-esel

maul-esel Apr 14, 2013

Contributor

👍

Contributor

maul-esel commented Apr 14, 2013

👍

@mojombo

This comment has been minimized.

Show comment
Hide comment
@mojombo

mojombo Apr 14, 2013

Contributor

I'm -1 on any out-of-the-box layout defaults. Jekyll should operate in obvious, unsurprising ways, and default layouts based on specifically named layout files is massively surprising (not to mention backwards incompatible).

I'm ok with adding the ability to set default layouts, though, but I think we should make it a power user feature, and make it very flexible. If we're going to do it, you should be able to set default layouts for given paths. Default layouts for sub-paths should override super-paths.

For example, if you want to default to page.html for everything but posts, and you want posts to default to post.html, then you could do:

layout_defaults:
 -
  layout: page.html
 -
  path: _posts
  layout: post.html

If you leave out the path, then it would apply to all paths.

This should also be pushed out to a post-1.0 release.

Contributor

mojombo commented Apr 14, 2013

I'm -1 on any out-of-the-box layout defaults. Jekyll should operate in obvious, unsurprising ways, and default layouts based on specifically named layout files is massively surprising (not to mention backwards incompatible).

I'm ok with adding the ability to set default layouts, though, but I think we should make it a power user feature, and make it very flexible. If we're going to do it, you should be able to set default layouts for given paths. Default layouts for sub-paths should override super-paths.

For example, if you want to default to page.html for everything but posts, and you want posts to default to post.html, then you could do:

layout_defaults:
 -
  layout: page.html
 -
  path: _posts
  layout: post.html

If you leave out the path, then it would apply to all paths.

This should also be pushed out to a post-1.0 release.

@maul-esel

This comment has been minimized.

Show comment
Hide comment
@maul-esel

maul-esel Apr 14, 2013

Contributor

I was skeptical on the page and post layout defaults too but I left them as they are.

The default for some path is quite interesting, in fact I thought of sth. like that for my current project but thought that might be too complicated. However, I find the YAML syntax you showed quite unintuitive.

An other way to handle it would be directory-specific config files (like .htaccess for apache), but I'm not sure if that doesn't clutter up the config handling too much. Also, besides layouts, what could one set per-directory? include, exclude?

Otherwise, it would be simpler to write sth. like

layout_defaults:
    *: page
    _posts: post

Though not much more intuitive, potentially ambiguous, ...

Also: are the paths relative to the source dir or globs (like exclude) ? And would it make sense still to differentiate between default page layouts and posts as the latter can also be in some/subfolder/_posts ?

If nobody else is specifically interested in realizing sth. like that and I get some feedback I will look into it later this week or next week.

Contributor

maul-esel commented Apr 14, 2013

I was skeptical on the page and post layout defaults too but I left them as they are.

The default for some path is quite interesting, in fact I thought of sth. like that for my current project but thought that might be too complicated. However, I find the YAML syntax you showed quite unintuitive.

An other way to handle it would be directory-specific config files (like .htaccess for apache), but I'm not sure if that doesn't clutter up the config handling too much. Also, besides layouts, what could one set per-directory? include, exclude?

Otherwise, it would be simpler to write sth. like

layout_defaults:
    *: page
    _posts: post

Though not much more intuitive, potentially ambiguous, ...

Also: are the paths relative to the source dir or globs (like exclude) ? And would it make sense still to differentiate between default page layouts and posts as the latter can also be in some/subfolder/_posts ?

If nobody else is specifically interested in realizing sth. like that and I get some feedback I will look into it later this week or next week.

@parkr parkr reopened this Apr 14, 2013

@maul-esel

This comment has been minimized.

Show comment
Hide comment
@maul-esel

maul-esel Apr 15, 2013

Contributor

@parkr: Most importantly, if we gonna remove the post and page layout defaults, that should be done before 1.0 is shipped. Removing them when people have started using them is a major incompatibility. As long as it's only been in the beta that's not so much of a problem.

Contributor

maul-esel commented Apr 15, 2013

@parkr: Most importantly, if we gonna remove the post and page layout defaults, that should be done before 1.0 is shipped. Removing them when people have started using them is a major incompatibility. As long as it's only been in the beta that's not so much of a problem.

@parkr

This comment has been minimized.

Show comment
Hide comment
@parkr

parkr Apr 15, 2013

Member

Yeah. @mojombo, why don't we strip Page- and Post-based defaults for 1.0 and put this on the docket for 1.1.

Member

parkr commented Apr 15, 2013

Yeah. @mojombo, why don't we strip Page- and Post-based defaults for 1.0 and put this on the docket for 1.1.

@maul-esel

This comment has been minimized.

Show comment
Hide comment
@maul-esel
Contributor

maul-esel commented Apr 15, 2013

@trans

This comment has been minimized.

Show comment
Hide comment
@trans

trans Apr 15, 2013

Contributor

Why are you going backwards? Sensible defaults for page and post layouts are quintessential "convention over configuration". Why would you want to revert to forcing every page to explicitly configure a layout?

Defaulting to page and post for page and post layouts is about the least surprising thing imaginable. What is more surprising is when everyone makes up their own file name so there is no conventional pattern. Moving between different Jekyll sites one constantly has to ask, what are the primary layouts for this site: page, post, main, default, standard, layout, page_layout, post_layout, layout_main, etc.

Contributor

trans commented Apr 15, 2013

Why are you going backwards? Sensible defaults for page and post layouts are quintessential "convention over configuration". Why would you want to revert to forcing every page to explicitly configure a layout?

Defaulting to page and post for page and post layouts is about the least surprising thing imaginable. What is more surprising is when everyone makes up their own file name so there is no conventional pattern. Moving between different Jekyll sites one constantly has to ask, what are the primary layouts for this site: page, post, main, default, standard, layout, page_layout, post_layout, layout_main, etc.

@parkr

This comment has been minimized.

Show comment
Hide comment
@parkr

parkr Apr 15, 2013

Member

@trans If you're moving from Jekyll pre-1.0 to Jekyll 1.0, you'll be surprised. I'd bet anything that'd be true. The default should be nil unless explicitly set, as it was. I was hesitant about accepting the page and post layout defaults in the first place, seems that it was the wrong choice to accept it! This is ultimately @mojombo's call. Out-of-the-box layout defaults are "magic," and the less magic we introduce, the fewer frustrations are likely to occur.

Member

parkr commented Apr 15, 2013

@trans If you're moving from Jekyll pre-1.0 to Jekyll 1.0, you'll be surprised. I'd bet anything that'd be true. The default should be nil unless explicitly set, as it was. I was hesitant about accepting the page and post layout defaults in the first place, seems that it was the wrong choice to accept it! This is ultimately @mojombo's call. Out-of-the-box layout defaults are "magic," and the less magic we introduce, the fewer frustrations are likely to occur.

@tofumatt

This comment has been minimized.

Show comment
Hide comment
@tofumatt

tofumatt Apr 15, 2013

So either I missed some documentation or it's not obvious, but I didn't know about the post and page defaults. I totally agree and think those are sane defaults and should be left in.

Sorry for opening this can of worms.

tofumatt commented Apr 15, 2013

So either I missed some documentation or it's not obvious, but I didn't know about the post and page defaults. I totally agree and think those are sane defaults and should be left in.

Sorry for opening this can of worms.

@parkr

This comment has been minimized.

Show comment
Hide comment
@parkr

parkr Apr 15, 2013

Member

Don't be sorry, it's important. One thing I hate about frameworks like rails is how magical it is. It works if you dot your i's and cross your t's but will wreak havoc if you forget something or if our defaulting code breaks on an edge case. If I set my front-matter to...

layout: 
title: Hi

... jekyll may default to post or page default even though I explicitly asked it not to. I'd rather as the user to turn things on than to have to try to turn them off.

I think generators are the solution here, not out-of-the-box layout defaults.

Member

parkr commented Apr 15, 2013

Don't be sorry, it's important. One thing I hate about frameworks like rails is how magical it is. It works if you dot your i's and cross your t's but will wreak havoc if you forget something or if our defaulting code breaks on an edge case. If I set my front-matter to...

layout: 
title: Hi

... jekyll may default to post or page default even though I explicitly asked it not to. I'd rather as the user to turn things on than to have to try to turn them off.

I think generators are the solution here, not out-of-the-box layout defaults.

@mojombo

This comment has been minimized.

Show comment
Hide comment
@mojombo

mojombo Apr 15, 2013

Contributor

@trans Jekyll is not Rails. Convention over configuration is not our motto. Simplicity and obviousness are what Jekyll cares about. Out of the box, Jekyll should be brutally obvious in how it functions. You ask Jekyll to apply a layout to a page or post and it does it. You don't ask it to apply a layout and it doesn't. Later on, when you realize that applying a default layout to a set of pages/posts would be better, I'd love to support that and make it possible.

Backwards compatibility is also extremely important for GitHub Pages, and I don't want this 1.0 release to turn into a shitshow of "why did my site totally break and do surprising things when all I did was push like normal?" Enabling out-of-the-box layout defaults will cause this. How many sites out there do you think already use post.html as their posts layout? How many of them use page.html as a layout file but don't want it applied to EVERY SINGLE PAGE? I'm guessing it's non-zero, and the alternative of keeping Jekyll obvious but still allowing for default layouts is, in my mind, a better solution anyhow.

Contributor

mojombo commented Apr 15, 2013

@trans Jekyll is not Rails. Convention over configuration is not our motto. Simplicity and obviousness are what Jekyll cares about. Out of the box, Jekyll should be brutally obvious in how it functions. You ask Jekyll to apply a layout to a page or post and it does it. You don't ask it to apply a layout and it doesn't. Later on, when you realize that applying a default layout to a set of pages/posts would be better, I'd love to support that and make it possible.

Backwards compatibility is also extremely important for GitHub Pages, and I don't want this 1.0 release to turn into a shitshow of "why did my site totally break and do surprising things when all I did was push like normal?" Enabling out-of-the-box layout defaults will cause this. How many sites out there do you think already use post.html as their posts layout? How many of them use page.html as a layout file but don't want it applied to EVERY SINGLE PAGE? I'm guessing it's non-zero, and the alternative of keeping Jekyll obvious but still allowing for default layouts is, in my mind, a better solution anyhow.

@CoryG89

This comment has been minimized.

Show comment
Hide comment
@CoryG89

CoryG89 May 16, 2013

+1 for some version of this. I was going to use this for a simpler way to sync documentation from a repo's master branch to a repo's gh-pages branch created by the Automatic Page Generator.

CoryG89 commented May 16, 2013

+1 for some version of this. I was going to use this for a simpler way to sync documentation from a repo's master branch to a repo's gh-pages branch created by the Automatic Page Generator.

@kidlj

This comment has been minimized.

Show comment
Hide comment
@kidlj

kidlj Nov 2, 2013

so, can we set default layout for _posts now?

kidlj commented Nov 2, 2013

so, can we set default layout for _posts now?

@parkr

This comment has been minimized.

Show comment
Hide comment
@parkr

parkr Dec 5, 2013

Member

Nope. Need to get #1527 merged first. Closing this in favour of that PR.

Member

parkr commented Dec 5, 2013

Nope. Need to get #1527 merged first. Closing this in favour of that PR.

@parkr parkr closed this Dec 5, 2013

@chunpu chunpu referenced this issue Jan 10, 2015

Open

jekyll小结 #20

@jekyll jekyll locked and limited conversation to collaborators Feb 27, 2017

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