enable the use of folders inside the _layout path #1622

Merged
merged 3 commits into from Oct 11, 2013

Projects

None yet

6 participants

@blackjid
Contributor
blackjid commented Oct 8, 2013

I want to be able to have a more flexible and tidy structure in the _layout folder

something like this

├── _layouts
|   ├── posts
|   |   ├── type1.html
|   |   └── type2.html
|   ├── default.html
|   └── post.html

And call them in the post front-matter like this

---
layout: posts/type1

---
@jaybe-jekyll
Member

I like this idea and concept. It would also provide consistency with _includes, as _includes already provides subfolder traversal and organization.

e.g.

./_includes/posts/meta.html

{% include posts/meta.html %}
@jaybe-jekyll
Member

WiP, potentially related or relatable: #1572

@parkr
Member
parkr commented Oct 8, 2013

What is the use-case for this and why is it needed?

@blackjid
Contributor
blackjid commented Oct 8, 2013

The example I gave in the issue is a use-case....

Probably the layouts inside the post folder would be something like developers.html, designers.html, writers.html. All layouts from different kind of people that can write in the blog. That could grow.

I also think it's counter-intuitive not to have the possibility to do this. I spend a lot before I realize the my posts weren't generated with the corresponding layout because of this limitation.

just my opinion, I hope this is good for others too..

@jaybe-jekyll
Member

Note/updated: * removed .html extension for clarity per @blackjid response comments

  1. Consistency and parity with _includes/DIR/... behavior
  2. Tidiness and organization
  3. An example use case:
    • One has a theming system and maintains a themed collection of layouts:
      • tar -xzvf aqua.tgz ./_layouts
      • (git ~/.themes/aqua ./_layouts/aqua)
$ ls -lR1 _layouts
aqua

_layouts/aqua:
forsale
pages
posts
recipes

_layouts/aqua/forsale:
forsale.html

_layouts/aqua/pages:
pages.html

_layouts/aqua/posts:
posts.html

_layouts/aqua/recipes:
recipes.html
recipes-overview.html
  • ./index.html
    • layout: aqua/pages
  • ./recipes/index.html
    • layout: aqua/recipes-overview
  • ./_posts/2013-10-08-lasagna-mmm.markdown
    • layout: aqua/recipes/recipes
@blackjid
Contributor
blackjid commented Oct 8, 2013

@jaybe-jekyll probably in the use of the layouts we should ommit the use of the .html extension

  • ./index.html
    • layout: aqua/pages
  • ./recipes/index.html
    • layout: aqua/recipes-overview
  • ./_posts/2013-10-08-lasagna-mmm.markdown
    • layout: aqua/recipes/recipes
@parkr
Member
parkr commented Oct 8, 2013

@jaybe-jekyll's use-case of a theme is really compelling. I'd definitely keep the extension in the layout declaration at the top of a page or post.

I'm curious: @cobyism, what do you think of this? @benbalter?

@blackjid
Contributor
blackjid commented Oct 8, 2013

Probably is a little outside the main topic, but @parkr why keep the extension? The jekyll documentation, in the front-matter section, show not to use the extension, just the name of the layout, when using at the top of a post...

It says about the layout property, If set, this specifies the layout file to use. Use the layout file name without the file extension

This is just out of curiosity...

---
layout: post
title: Blogging Like a Hacker
---
@parkr
Member
parkr commented Oct 8, 2013

Whoop, you're totally right. My b. I was thinking by not allowing for the extension you're limiting the number of possible file types that layouts can be but we already do that (layouts can really only be HTML) so omitting the file extension is good.

TL;DR as long as it's not a change in preexisting behaviour (wrt extname), I'm OK with it.

@parkr parkr closed this Oct 8, 2013
@parkr parkr reopened this Oct 8, 2013
@parkr
Member
parkr commented Oct 8, 2013

👍 @mattr-?

@jaybe-jekyll
Member

(Not) to muddy the waters or introduce scope creep, but for the purposes of stimulating creativity and additional thoughts: (this would surely require additional work and at the core level)

  • ./_config-yml
    • theme: aqua
  • ./_recipes/index.html
    • layout: recipes/recipes-overview

Internal logic: if site.theme, then (default) layout=_layouts/site.theme/page.layout

  • or, overridden, via:
    • ./recipes/index.html
      • theme: velvet
      • layout: recipes/recipes-overview

Internal logic: if page.theme, then layout=_layouts/page.theme/page.layout

I suppose the grander, higher-level point may be, theming support. ... the ability to quickly and easily have globally and or locally installed themes, to keep and apply as desired, flexibly.

$ cd _layouts

$ git clone themes.example.com/jekyll/aqua ./aqua

Further, some potential rules/guidelines in place for theme designers/providers:

  • Required: page.html, post.html, default.html
  • If a page/post asks for a theme/layout that does not exist, default to something sane versus throwing an error. Or not.
@parkr
Member
parkr commented Oct 8, 2013

@jaybe-jekyll I was thinking about that, too, but I don't think that's what we're after here. Let's start out small and see how this feature is used before introducing the idea of a theme. :)

@parkr
Member
parkr commented Oct 8, 2013

@blackjid Would you mind creating a Cucumber feature to make sure you see the correct output when you specify that layout?

@blackjid
Contributor
blackjid commented Oct 8, 2013

This was my first experience on cucumber, I hope it's ok

@blackjid
Contributor
blackjid commented Oct 8, 2013

@parkr I don't know why it failed, it passed in my local checkout... any idea?

@cobyism
Member
cobyism commented Oct 9, 2013

@parkr Yeah, I think that this is probably not a bad idea, even if just for consistency with how you can invoke _includes. At the moment it’s possible to achieve similar namespacing of layouts using combinations of prefixes and hyphens (i.e. layout: posts-type1 instead of layout: posts/type1 in the very first example), but having proper support for directories will result in tidier filesystems, and that seems like a definite win. As long as the implementation doesn’t wind up unnecessarily complicated for some reason, I’d say 👍 😁

@mattr- mattr- merged commit e3f6d86 into jekyll:master Oct 11, 2013

1 check failed

default The Travis CI build failed
Details
@mattr- mattr- added a commit that referenced this pull request Oct 11, 2013
@mattr- mattr- Update history to reflect merge of #1622 110aeee
@mattr- mattr- added a commit that referenced this pull request Oct 11, 2013
@mattr- mattr- Allow nested subdirectories in the layouts folder
This is pull request #1622 implemented in this branch
e67e43e
@benbalter
Contributor

Can I pass a relative path here? e.g., ../../../../passwords.txt?

@parkr
Member
parkr commented Nov 2, 2013

@benbalter No, see line 125 of site.rb.

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