方法一:用Enjoy模板里的原样输出.
#[[ {{# if(d.status == 1){ }} ]]# <button class="layui-btn layui-btn-xs">正常</button> #[[ {{# } else { }} ]]# <button class="layui-btn layui-btn-primary layui-btn-xs">禁用</button> #[[ {{# } }} ]]#
方法二:自定义laytpl指令
@Override public void onRender(Env env, Scope scope, Writer writer) { if (exprList.length() > 1) { throw new ParseException("Wrong number parameter of #date directive, one parameters allowed at most", location); } String expr = ""; if(exprList.length() > 0) { expr = getParam(0, scope); } write(writer, " {{"+expr); stat.exec(env, scope, writer); write(writer, "}}"); } @Override public boolean hasEnd() { return true; }
#laytpl('#') if(d.status == 1){ #end <button class="layui-btn layui-btn-xs">正常</button> #laytpl('#') } else { #end <button class="layui-btn layui-btn-primary layui-btn-xs">禁用</button> #laytpl('#') } #end
好像也没方便多少... 不知道有没有更好的办法.
{{#
if(d.status == 1){ }}