Had a chance to try it out. The way Velocity accesses static methods is described here:
http://velocity.apache.org/engine/releases/velocity-1.6.2/developer-guide.html#supportforstaticclasses For Click you can do something like: public void onInit() { addModel("velocity", Velocity.class); } Then in your template you can access the resourceExists method as follows: #if ($velocity.resourceExists("/xyz.htm")) #parse(...) #end That said, the resourceExists method didn't work for me (not sure why), so I ended up writing my own method: public class Util { public static void resourceExists(String resourceName) { try { Context context = Context.getThreadLocalContext(); // First check on the servlet context path boolean hasTemplate = context.getServletContext().getResource(resourceName) != null; if (!hasTemplate) { // Second check on the classpath hasTemplate = ClickUtils.getResource(resourceName, Util.class) != null; } } catch (MalformedURLException e) { throw new RuntimeException(e); } return hasTemplate; } You can use it as follows: public void onInit() { addModel("util", Util.class); } Hope this helps. kind regards bob On Thu, Aug 13, 2009 at 2:24 PM, Prem Kurian Philip<[email protected]> wrote: >> I haven't tested myself but isn't the templateExists function part of >> the Velocity class? >> >> So you should do this instead: >> >> #if (Velocity.templateExists("empty.htm") >> #end >> >> Also it seems as if templateExists has been deprecated in favor of >> resourceExists. >> > > Bob, thanks a lot for taking the time to reply. > > I did actually try this earlier (Velocity.templateExists as well as > Velocity.resourceExists) and I was still getting the same parse error. > > I tried this: > #if (Velocity.templateExists("template.htm") == true) > #parse("template.htm") > #end > > As well as this: > > #if (Velocity.resourceExists("template.htm") == true) > #parse("template.htm") > #end > > The error I am getting: Page Parsing Error > > Source: /border-template.htm > Message: Was expecting one of: "[" , "{" , "(" , <WHITESPACE> , > <STRING_LITERAL> , "true" , "false" , <INTEGER_LITERAL> , > <FLOATING_POINT_LITERAL> , <IDENTIFIER> , "{" , <LOGICAL_NOT> > > Regards, > Prem > > -- http://incubator.apache.org/click/
