0

我编写了一个位于 /src 文件夹中的示例 java 文件。

public class Main {
  public static void main(String[] args){
    STGroupFile StgFile=new STGroupFile("template.stg");
    StgFile.delimiterStartChar = '$';
    StgFile.delimiterStopChar = '$';
    ST webtemp=StgFile.getInstanceOf("test");
    webtemp.add("x","whyyy");
    System.out.println(webtemp.render());
  }
}

我也有位于 /src 文件夹中的文件 template.stg

import "headers/header.stg" 
test(x) ::= << $included(x)$ >>

以及位于 /src/headers 文件夹中的文件 header.stg。

included(x) ::= << headers[$x$] >>

结果显然是

headers[whyyy]  

但是如果我尝试导入整个 headers 目录,使 template.stg 像这样:

  import "headers" 
  test(x) ::= << $included(x)$ >>
  • 包含的子模板不能使用...

我使用的 StringTemplate 版本是最新的 4.0.5 并且根据链接http://www.antlr.org/wiki/display/ST4/Differences+between+v3+and+v4导入目录是允许的..我甚至在/之前和/或之后使用过/ - 相对/绝对路径,但它不起作用:(请帮忙?谢谢:)

4

1 回答 1

3

你试过$header/included(x)$吗?

于 2012-04-25T15:32:31.033 回答