Building a template engine - starting point

Posted by Anirudh on Programmers See other posts from Programmers or by Anirudh
Published on 2012-06-29T07:12:52Z Indexed on 2012/06/29 9:22 UTC
Read the original article Hit count: 233

We're building a Django-based project with a template component. This component will be separate from the project as such and can be Django/Python, Node, Java or whatever works. The template has to be rendered into HTML. The templates will contain references to objects with properties that are defined in the DB, say, a Bus. For eg, it could be something like

[object type="vehicle" weight="heavy"]

and it would have to pull a random object from the DB fulfilling the criteria : type="vehicle" weight="heavy" (bus/truck/jet) and then substitute that tag with an image, say, of a Bus. Also it would have to be able to handle some processing. Eg:

What is [X type="integer" lte="10"] + [Y type="integer" lte="10"]

[option X+Y correct_ans="true"]

[option X-Y correct_ans="false"]

[option X+y+1 correct_ans="false"]

The engine would be expected to fill in a random integer value <= 10 for X and Y and show radioboxes for each of the options. Would also have to store the fact that the first option is the correct answer.

Does it to make sense to write something from the scratch? Or is it better to use an existing templating system (like Django's own templating system) as a starting point? Any suggestions on how I can approach this?

© Programmers or respective owner

Related posts about design

Related posts about design-patterns