Layout: default

Hello,

I’m a little confused about frontmatter in _layouts.

in _layouts, i have this files:
default.html
home.html
post.html

When adding this code in home.html:

---
layout: default
---

So, if i understand, the layout from home.html change to default.html in the browser?

What is the reason you want to add this frontmatter in home.html instead of using default.html directly?

I’m not much of a fan of that but have seen it in some themes, it is just a way to chain things into more and more complex layouts. it can be difficult to understand what they are doing when they are calling another layout from the set layout. But by doing it that it is running the page content thru one layout, and then that layout is going thru another layout.

1 Like

Ah okay,
So it is not necessary using this :slight_smile:

It is neccesary it the default layout renders a basic common place for all content like the footer, header, netadata…
And the post or page layout just render other parts.

You could use includes instead and include that headers in every layout instead.

1 Like

Oh, okay. Good to know!
Trying learn a lot as beginner, so i can build my own theme :slight_smile:

yes - I prefer to use includes for the header and footer, layout is everything inbetween.

1 Like

Here’s an example of how to chain layouts. As @rdyar mentioned, it all comes down to preference and how much you want to repeat yourself.

If you chain the layouts you can have a default.html layout that has header, footer, etc. includes. Then you can build child layouts that reference that, where you may have subtle differences in the main part of the layout.

This is nice because then you’re not doing

{% include header.html %}
{% include footer.html %}

In each of your layouts. Those includes happen in default.html which cascades down to any child layouts the reference it. It’s less code, less repeating yourself, and less chance for errors.

1 Like

@mmistakes,

Thanks a lot for this clear and understandable answer.
I’m new with Jekyll, and do a lot of ‘trail-and-error’ with Jekyll, so i learn and try understanding how all the things work developing Jekyll.

I’m a Wordpress specialist and trying to understand why Jekyll is so populair and what it makes so special. I know it is secure and fast and can used for Github pages, but i asked myself if Jekyll a good choice for me. At the moment it feels nice experimenting with Jekyll, but i missed some ‘dynamic pages’ (users login, comments, searching, … ) i think some things is possible with Javascript. Hoping that some of this options planned in the future.

Btw i read with a lot of interest your blog articles about Jekyll :grinning:

Not sure if more dynamic possibilities are in the works for Jekyll. It’s best to thing of Jekyll as a tool that helps build flat HTML files.

It’s not creating dynamic views that pull data from a database like say Wordpress does with PHP and mySQL. Jekyll’s primary concern is taking source files (usually Markdown) and converting them to HTML.

1 Like

might try https://www.gatsbyjs.org/ if you want the dynamic stuff.

Trying a lot of cms-systems, also flatfiles, but is difficult wich is the best, and every system has limitations.
But I see so mutch popularity about Jekyll.
The big pro for me is the active community, and a lot of plugins.
Few weeks ago trying Middleman, but i see less activity, also the update cycle, and this scares me.

GatsbyJS works with React, i think :roll_eyes:
React is not my thing. I read about it, and it’s look great, but to difficult for me.

Jekyll is a blog-aware platform, and most users used as blog-platform, but are there examples about advanced Jekyll-websites so i can see how flexible Jekyll is?

what does advanced mean? you aren’t going to find something with a login page very easily, some have comments, there was a super cool project called staticman allowed comments on any static site that worked great until this year at which point it started to have issues. Not sure it still works. Using disqus is easy enough though.

my shops website uses jekyll, https://prolabprints.com/ definitely not saying it is advanced though - but it is not at all a blog if that is what you mean.

Another site I have pulls some info from the GH api to display issues, that was fairly easy to do with JS. https://simpleordersystem.com/issues/

the Share Your Site thread has some good looking sites.

I’ve always liked the documentation theme by I'd rather be writing:

https://idratherbewriting.com/documentation-theme-jekyll/

as well as mademistakes blog, but that is a blog so not what you want I suppose.

Hi @rdyar,

Yes,yes, thats what i mean. Other websites (instead blogs), made with Jekyll.
I really like seeing how actively other people developing Jekyll, making very flexible for other purposes.
It gives me idea’s, ‘okay it is possible with Jekyll’. I know some people saying, ‘it is not for Jekyll, choose another system for that!’.
I think with some effort, and adding some JS, you can build mostly everything with Jekyll.
But i like to see what other people do and share experience with Jekyll.
Last days reading blogs about people using Jekyll, very interesting! I don’t know if here are people only develop Jekyll websites for clients, and what experience they has. I’m working with Wordpress and is simple for some ‘non-tech’-clients adding posts. After a lot of google search, finding Jekyll-admin plugin, it is a step closer for a client adding his own posts without tech-knowledge.
Btw, your websites are awesome, adding https://idratherbewriting.com/documentation-theme-jekyll/ to my favorites!

UPDATE: I knwo about Disques, but its not free? Years ago building a Drupal website and adding comments with the Facebook comments plugin.

Great thing about static building is deployment simplicite: it works every where.
It is fast, you don’t need a server with lot of power and memory.

It is simple to maintain. You don’t have to fight with server updates, incompatibility of library versions, configurations in the server, etc.

If it works in your computer, it will work in the server.

Another attractive features is the ability to have all your site in your own computer.
I can show it to any body every where.

Implementing dynamic behaviour is harder. If you need a lot of interaction with visitors, I think it is not the best option.

Comments may be implemented though other external services (or other packages installed in your server). Email form can be implemented that way too.

But if you want a forum, for example, a static generator is not obviously the way to go.

I think Jekyll and other static site gens must evolve yet.

In order to be able to display content more dynamically, they should completely separate content from displaying (which it not the case now in the final version of the site).

Content should be saved as json or other structured format static data files.

Displaying should be rendered using JavaScript from that files.
HTML files should have justa an ides of pages they must show and JavaScript to recover content in that pages and show it.

Thus you could have things like continous scrolling index pages for large sites with lots of pages.
Or complex searches in your site like “pages with this set of tags in category 1 and 2 but which does not have this other tag”.

You cannot do that, now. You can use google to do your searches, but you cannot implement it in your site with external services.

Well may be you can implement it using a custom with with heavy work in JavaScript and a plugin to generate the data files (not sure of this as each source file just renders one output file), but you have not aid from Jekyll to do that.

1 Like

Indeed, that’s ideal. However, if you add dependencies, it stops being that simple. For example, an outdated Node.js package can cause a site that works fine locally to fail online.