docs: demo for globals, for #286

This commit is contained in:
harttle
2020-12-22 23:19:09 +08:00
parent 626f911503
commit 7b909c22a1
4 changed files with 14 additions and 6 deletions
+1
View File
@@ -0,0 +1 @@
<small>{{title}}</small>
+7
View File
@@ -0,0 +1,7 @@
<html>
<head><meta name="title" content="{{title}}"></head>
<body>
{% block %}{% endblock %}
{% render "footer.liquid" %}
</body>
</html>
+3 -3
View File
@@ -2,7 +2,8 @@ const { Liquid } = require('liquidjs')
const engine = new Liquid({
root: __dirname,
extname: '.liquid'
extname: '.liquid',
globals: {title: 'LiquidJS Demo'}
})
engine.registerTag('header', {
@@ -17,8 +18,7 @@ engine.registerTag('header', {
})
const ctx = {
todos: ['fork and clone', 'make it better', 'make a pull request'],
title: 'Welcome to liquidjs!'
todos: ['fork and clone', 'make it better', 'make a pull request']
}
engine.renderFile('todolist', ctx)
+3 -3
View File
@@ -1,7 +1,7 @@
{%header content: "welcome to liquid" | capitalize%}
{% layout 'html.liquid' %}
{%header content: title | capitalize%}
<ul>
{% for todo in todos %}
<li>{{forloop.index}} - {{todo}}</li>
{% endfor %}
</ul>
</ul>