Search code examples
jekyllliquid

if statement in jekyll + liquid create codeblock instead of intened html tags


Hey I have for each loop in Jekyll which in each increment increase the count of a variable phdCount which I do like this: {% assign phdCount = phdCount | plus:1 %}. When phdCount == 3 is true I won't to close a boostrap row and start a new so, which I attempt to do like this:

{% if phdCount == 3 %}
    </div>
    <div class="row">
{% endif %}

Which should give me closing and opening div tag in my HTML. But what I get instead is a code block in HTML containing the tags as shown: enter image description here

I have not included any custom gems or anything in /lib. Any ideas on how to solve this?


Solution

  • The page is rendering with a code block because of the indentation/spacing.

    {% if phdCount == 3 %}
        </div>
        <div class="row">
    {% endif %}
    

    should be

    {% if phdCount == 3 %}
    </div>
    <div class="row">
    {% endif %}
    

    That will remove the code block. However, the fact that the page is thinking there could be a code block and not just treating it strictly as HTML code means that there could be something else wrong with the page. If you're in a .md file trying to mix in HTML, then that could be where the code block could be coming from. If you're in a .html file, then something else could be the issue.

    Could you show the code surrounding the {% if %} block?