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({ const engine = new Liquid({
root: __dirname, root: __dirname,
extname: '.liquid' extname: '.liquid',
globals: {title: 'LiquidJS Demo'}
}) })
engine.registerTag('header', { engine.registerTag('header', {
@@ -17,8 +18,7 @@ engine.registerTag('header', {
}) })
const ctx = { const ctx = {
todos: ['fork and clone', 'make it better', 'make a pull request'], todos: ['fork and clone', 'make it better', 'make a pull request']
title: 'Welcome to liquidjs!'
} }
engine.renderFile('todolist', ctx) engine.renderFile('todolist', ctx)
+2 -2
View File
@@ -1,5 +1,5 @@
{%header content: "welcome to liquid" | capitalize%} {% layout 'html.liquid' %}
{%header content: title | capitalize%}
<ul> <ul>
{% for todo in todos %} {% for todo in todos %}
<li>{{forloop.index}} - {{todo}}</li> <li>{{forloop.index}} - {{todo}}</li>