views:

29

answers:

1

What I'm looking for would allow me to take something like this:

index.html.template:

<html>
<body>
<# include ("body.html.template") #>
</body>
</html>

body.html.template:

Hello World! <# include("text.txt") #>

text.txt:

4

And turn it into this:

<html>
<body>
Hello World! 4
</body>
</html>

While the example is HTML, I would probably end up using something like this in a lot of weird places. I think there are a number of preprocessors out there; is there a very basic one that's suited to this task?

+2  A: 

http://www.cheetahtemplate.org/

it is basically python statements embedded in template, so you have access to all python functionality. Small example:

#for $i in $range(10)
#set $step = $i + 1
$step.  Counting from 1 to 10.
#end for

will produce

0.  Counting from 1 to 10.
1.  Counting from 1 to 10.
...

this link documents include directive: http://www.cheetahtemplate.org/docs/users_guide_html/users_guide.html#SECTION000860000000000000000

aaa
@Georg point taken, description added
aaa
That could work, but it appears to only generate .py files by default. Do you have an example that generates HTML? I'm currently investigating the documentation...
Chris
@Chris actually default is Html. I use it to generate C++ code as well. they are 2 modes, compile and fill. You want later, checkout section 4.3 in documentation
aaa
@aaa sounds good. So from this it looks like I'd write cheetah compile --iext html.tmpl --oext html to generate html?
Chris
@Chris `cheetah fill a.tmpl` Should be sufficient to create a.html
aaa
@aaa Oh, I mean as a generic system so I could do cheetah compile --iext js.tmpl --oext js, for example. Thanks for the help!
Chris