Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if current page is homepage on Jekyll

Tags:

jekyll

There's any way to check if the current page is the homepage?

I want use h1 tag for the logo image only when the current page is the website base url.

like image 705
Christopher Avatar asked Mar 08 '15 22:03

Christopher


Video Answer


3 Answers

You can use page.url to check if the current page is your index page:

{% if page.url == "/index.html" %}
   <h1>...</h1>
{% endif %}
like image 200
Dennis Schubert Avatar answered Oct 22 '22 22:10

Dennis Schubert


Another option to manage this is adding page IDs to the yml frontmatter

{% if page.id == 'index' %}
  content
{% endif %}
like image 29
Chris Peak Avatar answered Oct 22 '22 21:10

Chris Peak


Along @Christopher's comment the best is if you test the page.layout. Because if permalink is set or in other circumstances the page.url can be "/index.html", "/index", or just simply "/". Therefore I think it's more robust:

{% if page.layout == 'home' %}
  <h1>logo</h1>
{% else %}
  <h2>smaller logo</h2>
{% endif %}
like image 24
Csaba Toth Avatar answered Oct 22 '22 20:10

Csaba Toth