开发者

erazor set variable

a little question about erazor https://github.com/ciscoheat/erazor i know this framwork is based on Razor template engine. http://weblogs.asp.net/scottgu/archive/2010/07/02/introducing-razor.aspx

i noticed the api doesn't fit exactly with Razor (ex: @for(a in p) differs from RAZOR)

this template system for haxe is very handy... i just don't know how to setup a variable like we do in templo ( :: set mock="tada!":: )

//@scope is mycontroller;
@{var mock = scope.getMock()}
@if(mock!=null){
//display some html
}
开发者_高级运维

any tips ? thx


The following snippet works:

import erazor.Template;
import neko.Lib;

class Main {
  static function main() {
    var template = new Template("@{var mock = scope.getMock();} @if (mock != null) { @mock }");
    Lib.print(template.execute( { scope : { getMock : function() return "hi" } } ));
    }
}

What you missed is that inside a code block all the statements must be correctly closed (missing ;). Also erazor is loosely based on Razor and uses the Haxe syntax for expressions.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜