Velocity Templates and Newlines
If you're reading this article you've probably encounted the same problem as I have. I was trying to put a newline '\n' character in the value of a variable in a Velocity template. Attempt 1: I assumed \n would work... ``` #if ( !$foo ) #set ( $foo = "There was no foo set in the Context.\nPlease do something about it." ) #end ``` This produced There was no foo set in the Context.\nPlease do something about it. as the value of $foo. Attempt 2: I just thought this was worth a shot :D ``` #if ( !$foo ) #set ( $foo = "There was no foo set in the Context. Please do something about it." ) #end ``` And the template failed to compile Solution: Basically, the easiest way I found is to place the newline, carriage return or other special character in the context. java public Template handleRequest( HttpServletRequest request, HttpServletResponse response, Context context ) { ... context.put( "nl", "\n" ); context.put( "cr", "\r" ); ... } And in your template: ``` #if ( !$foo ) #set ( $foo = "There was no foo set in the Context.${nl}Please do something about it." ) #end ``` Maybe not the best solution but it works for me. If you expect to use it across your entire application I suggest you override VelocityServlet.createContext in your Servlet to add these characters to every context in your application. Example: ```java
protected Context createContext( HttpServletRequest request, HttpServletResponse response ) { Context context = super.createContext( request, response ); context.put( "nl", "\n" ); context.put( "cr", "\r" ); return context; }
The Cutler.sg Newsletter
Weekly notes on AI, engineering leadership, and building in Singapore. No fluff.
Two Papers That Puncture the Hype
One paper shows frontier models degrade as context grows — even on trivial tasks. The other shows reasoning models hit a wall and think less as problems get harder. Read carefully, both point at the same engineering response.
The 30 Principles for Agentic Engineering — Part 5: Calibration and Reality
Principles 26–30. The calibration layer that catches what the rest of the framework would miss: a PR-noise budget, independent verification, model-swap regression discipline, the 15-tool-call rule, and protecting junior development.
The 30 Principles for Agentic Engineering — Part 3: The Harness
Principles 15–20. The harness configuration that keeps the kernel and lifecycle cheap: CLAUDE.md under 200 lines, hooks for real incidents, skills that auto-invoke, subagent isolation, pinning, and Stage 5 distribution.