如何在Jekyll Markdown页面中转义Liquid模板渲染?
Hey there! If you want to make sure Liquid doesn't process your {{ content }} tag and instead renders it as plain text on the page, here are the most reliable methods to do that:
1. Use the {% raw %} and {% endraw %} Tags
This is the simplest and most straightforward approach, especially when you have blocks of content that shouldn't be parsed by Liquid. Just wrap the code you want to escape in these tags:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Example Title</title> </head> <body> <div id="app"> {% raw %} {{ content }} {% endraw %} </div> </body> </html>
The raw tag tells Liquid to completely ignore everything between it and {% endraw %}, so your {{ content }} will show up exactly as written in the final HTML.
2. Manually Escape Individual Liquid Delimiters
If you only need to escape a single tag (instead of a whole block), you can output the Liquid delimiters ({{ and }}) directly by wrapping them in Liquid output tags:
<div id="app"> {{ '{{' }} content {{ '}}' }} </div>
Here, Liquid will process {{ '{{' }} to output the literal {{, and {{ '}}' }} to output }}. The end result is the plain text {{ content }} on your page.
A Quick Note: Avoid Confusing with HTML Escaping
Don't mix this up with the escape filter — that's used to escape HTML special characters (like < to <), not to prevent Liquid from parsing its own tags. For your use case, the raw tag method is almost always the best choice.
内容的提问来源于stack exchange,提问作者Christopher Murphy

