velocity
velocity copied to clipboard
define变量的引用问题
below is library.vm:
#macro(render $subchannel)
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style tyle="text/css">
## 页面css
$!q_css
</style>
</head>
<body>
## 页面html
$!q_body
## 页面js
$!q_js
</body>
</html>
#end
{code}
below is index.vm:
#define( $q_css )
body{background:green;}
#end
#define( $q_body )
hello word!
#end
#define( $q_js )
<script>
var nimei = "nimei";
</script>
#end
#render('hotel')
在java里,render index.vm能输出$q_js,$q_css,$q_body,这样也是比较合理的
在engine-ref.js里
Reference: function(node) {
// call define
if (common.isId(node)) {
var name = node.object.name
if (name in this.template.__define) {
var def = this.template.__define[name]
var result = this[def.type](def)
if (result.stats !== STATS.SUCCESS) {
// at where the #define is called
result.stack.push(common.getRealLoc([this.template, node.pos]))
}
return result
}
}
是不是做成 return this.template._define[xxx] <- this.template.__parent.__define这样逐层查找比较合理,且和java更加吻合