Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cannot remove line break generated by for loop in jekyll

Tags:

html

jekyll

I am unable to remove the new line character that is generated by jekyll's for loop from the following:

<br/><ul class="post-list">
{% for post in site.tags[page.tag] %}
<li>
<h2>{{ post.date | date: "%b %d %Y" | append: post.excerpt }}</h2>
</li>
{% endfor %}
</ul>

I have looked all over SO and, though I see that this is a issue that people get stuck on, it is not clear to me whether it is possible to remove this newline without writing something that would remove the newline characters from the jekyll generated HTML after the fact. I would prefer not to have to do that. Does anyone know how to get post.date and post.excerpt to generate without a new line in between?

like image 931
caseyanderson Avatar asked Oct 30 '25 15:10

caseyanderson


1 Answers

Im not sure if I understood your question correct. I guess, with new line character you mean some obsolete empty lines in the generated HTML.

At least with newer versions of liquid, the solution is to replace {% by {%-.

<br/><ul class="post-list">
{%- for post in site.tags[page.tag] -%}
<li>
<h2>{{ post.date | date: "%b %d %Y" | append: post.excerpt }}</h2>
</li>
{%- endfor -%}
</ul>

More details can be found here.

like image 173
knut Avatar answered Nov 01 '25 14:11

knut



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!