一,模板引擎下载
动态web网页开发是Web开发中一个常见的场景,需要使用模板技术来实现。而Lua中也有许多模板引擎,如目前使用的lua-resty-template,可以渲染很复杂的页面。如果学习过JavaEE中的servlet和JSP的话,应该知道JSP模板最终会被翻译成Servlet来执行;而lua-resty-template模板引擎可以认为是JSP,其最终会被翻译成Lua代码,然后通过ngx.print输出。
模板引擎第三方模块安装:
#下载lua-resty-template模块
cd /usr/local/nginx/webapps/example/lualib/resty/
wget https://raw.githubusercontent.com/bungle/lua-resty-template/master/lib/resty/template.lua
#下载html.lua模块
cd /usr/local/nginx/webapps/example/lualib/resty/
mkdir html
cd /usr/local/nginx/webapps/example/lualib/resty/html
wget https://raw.githubusercontent.com/bungle/lua-resty-template/master/lib/resty/template/html.lua
二,模板引擎语法