Jekyll - changing _config.yml variables in post layout
In mine config.yml
I have:
...
showheader: "yes"
And in my template default.html
, I have a condition to show the include header:
<!DOCTYPE html>
<html>
{% include head.html %}
<body>
{% if site.showheader == "yes" %}{% include header.html %}{% endif %}
<main class="page-main">
{{ content }}
</main>
{% include footer.html %}
</body>
</html>
In my template, post.html
I don't want to show header.html
, so I try this:
---
layout: default
---
{{ site.showheader = "no" }}
<article class="post">
<header class="post-header">
<h1 class="post-h1" href="{{ post.url | prepend: site.baseurl }}">{{ page.title }}</h1>
<p class="post-meta">{{ page.date | date: "%b %-d, %Y" }}{% if page.author %} • {{ page.author }}{% endif %}{% if page.meta %} • {{ page.meta }}{% endif %}</p>
</header>
<p class="post-p">{{ content }}</p>
<footer class="post-footer">
<p class="rss-subscribe">subscribe <a href="{{ "/feed.xml" | prepend: site.baseurl }}">via RSS</a></p>
</footer>
</article>
But it just doesn't work and no one returned an error. In Jekyll, is it possible to change the value of a variable set to _config.yml
from the template layout post.html
?
source to share
You can't seem to reassign the value site.variable
. {% assign site.showheader = false %}
does not work if showheader: true
installed in _config.yml
.
If you want to display the title depending on the page you are on, just set the variable in the initial question of the page.
In index.html:
---
showheader: true
layout: default
---
In the message:
---
showheader: false
layout: default
---
In _layouts / default.html
{% if page.showheader == true %}
header
{% endif %}
source to share