0
저는 간단한 NVvelocity 템플릿을 만들지 만 변수가 있는지 테스트하는 방법을 알 수는 없습니다.이 예제에서는 테스트하고 싶습니다. 컨텍스트에 callwed라는 속성이 포함되어있는 경우.NVelocity 템플릿에서 어떻게 부동산의 존재 여부를 테스트합니까
해킹 된 foreach 루프와 동일한 기능을 구현할 수 있지만 더 좋은 방법이 있는지 궁금합니다.
Velocity.Init();
VelocityContext context = new VelocityContext();
context.Put("from", "somewhere");
context.Put("to", "someone");
context.Put("subject", "Welcome to NVelocity");
String s = @"From: $from To: $to Subject:
#if($context.ContainsKey('User'))
We Have a User
#else
No User Found
#end";
var sw = new System.IO.StringWriter();
Velocity.Evaluate(context, sw, "", s);
string merged = sw.ToString();