Order of Interpretation

I found a documentation that explains the order of interpretation. The documentation is updated last on April 2020, and I’m curious if it is still valid.

The reason I am curious of the validity is because I think if the order explained on the documentation is correct, the code below should not be rendered correctly.

Here’s a simple layout file and a content file.

_layouts/my-layout.html

<!DOCTYPE html>
<html lang="ko">
<head>
    <title>{{ page.title | append: " | " | append: site.title}}</title>
</head>
<body>
    <p id="title">{{ page.title }}</p>
    <div id="content">{{ content }}</div>

    <style>
        #title {
            font-weight: bold;
            font-size: 1.1em;
            text-align: center;
            padding-top: 1em;
            padding-bottom: 1em;
            background-color: lightsalmon;
        }

        #content {
            padding: 1em;
            background-color: lightgreen;
        }
    </style>
</body>
</html>

test.md

---
title: test page
layout: my-layout
---

This is a test page.

As you can see, the layout file is using liquid to print out the title of the page. According to the documentation, the order of interpreting liquid is prior to the one of merging layout file, so the title of the page({{ page.title }}) should not be printed out.

However, when I tested the code, it worked as I wished. The title of the page is printed so nicely.

Is there anything I’m missing? Please help me.

Thank you in advance.

You may have misunderstood the Order of Interpretation documentation.
The gist of the document can be summarized as following:

Process Liquid in current page
              ⬇
Convert text in current page into designated markup
              ⬇
Inject converted output into designated layout
              ⬇
Process Liquid layout
              ⬇
Repeat previous two steps if current layout uses a parent layout

So, irrespective of where {{ page.title }} is, the final result will always be fully rendered markup.

1 Like

Thank you for your reply.

So, you mean that Liquid is interpreted twice – only on the current page first, and on the content-layout-merged file again? And {{ page.title }} is interpreted on the second Liquid interpretation?

Do I understand it correctly? Thank you.

Yes, that is correct. Liquid is interpreted more than once.
You’re welcome.

1 Like