g-Off.net | Geoffrey Foster

Template Engine

A Cocoa template engine based upon Django's templating engine.

Currently supported features:

  • foreach loop statements: foreach x, y, z in points
  • for loops: for 1 to 5
  • if/else statements: if (x == y) and (y != z)
  • variable assignment: let x := 7
  • extends tag (for template inheritance): extends "base.html"
  • block tag: for replacing blocks in parent template
  • include tag: for including contents of another template file
  • load tag: for loading additional tags and filters
  • Math operations: +-*/
  • Logical operators: and, or, not, ==, !=, <, >, <=, >=

Usage:

GFTemplate *template = [[GFTemplate alloc] initWithTemplatePath:@"/Some/path/to/file.txt"];
NSMutableDictionary *variables = [NSMutableDictionary dictionary];
// Add variables to the context dictionary here
[variables setObject:[NSNumber numberWithInteger:5] forKey:@"x"];
[variables setObject:[NSNumber numberWithInteger:-6] forKey:@"y"];
NSString *results = [template render:variables];

Source code is available here. Licensed under the 3-clause license ("New BSD License").

Share and Enjoy:
  • Digg
  • Facebook
  • Google Bookmarks
  • LinkedIn
  • Reddit
  • Twitter
Comments (2) Trackbacks (0)
  1. Hey found your template engine TKTemplate. What is the license for it, BSD?

  2. I’ve updated page to show that it’s under the 3-clause BSD license. Also noticed that they link I had to the source code was wrong. I have somewhat abandoned this project, but please feel free to fork on BitBucket and submit patches. Having another contributor would help spur my desire to work on it again =)


Leave a comment


No trackbacks yet.