我找到解决我的问题,但不能与虚拟文件类。如果我在游戏中创建自定义标签,那么它可能会是空白,这将取代我的视图中的extend
标记。
如果你看一下游戏的源代码,你可以找到我只需要工作 FastTags class, line 319
public static void _extends(Map<?, ?> args, Closure body, PrintWriter out, ExecutableTemplate template, int fromLine) {
try {
if (!args.containsKey("arg") || args.get("arg") == null) {
throw new TemplateExecutionException(template.template, fromLine, "Specify a template name", new TagInternalException("Specify a template name"));
}
String name = args.get("arg").toString();
if (name.startsWith("./")) {
String ct = BaseTemplate.currentTemplate.get().name;
if (ct.matches("^/lib/[^/]+/app/views/.*")) {
ct = ct.substring(ct.indexOf("/", 5));
}
ct = ct.substring(0, ct.lastIndexOf("/"));
name = ct + name.substring(1);
}
BaseTemplate.layout.set((BaseTemplate) TemplateLoader.load(name));
} catch (TemplateNotFoundException e) {
throw new TemplateNotFoundException(e.getPath(), template.template, fromLine);
}
}
如何利用现有的要使用重载的方法TemplateLoader.load(String, String)
它接受模板字符串(对比原执行到文件名),然后设置它以 BaseTemplate.layout.set(...)
方法。当然,首先我需要通过HTTP请求从远程服务器获取模板。