检查当前页面是否是Jekyll的主页

Chr*_*her 26 jekyll

有什么方法可以检查当前页面是否是主页?

我希望h1仅当当前页面是网站基本网址时才使用标记作为徽标图像.

小智 27

您可以page.url用来检查当前页面是否是您的索引页面:

{% if page.url == "/index.html" %}
   <h1>...</h1>
{% endif %}
Run Code Online (Sandbox Code Playgroud)

  • 我最终使用if {%if page.url =="/"%}.其余的不适合我. (22认同)
  • 我使用`{%if page.layout =='home'%}`但你的答案也是正确的.谢谢! (4认同)

小智 11

管理此问题的另一个选择是将页面ID添加到yml前端

{% if page.id == 'index' %}
  content
{% endif %}
Run Code Online (Sandbox Code Playgroud)