2

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?

Chris
  • 5,876
  • 3
  • 43
  • 69

1 Answers1

2

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

Anycorn
  • 50,217
  • 42
  • 167
  • 261
  • 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 Jul 21 '10 at 15:25
  • @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 – Anycorn Jul 21 '10 at 15:31
  • @aaa sounds good. So from this it looks like I'd write cheetah compile --iext html.tmpl --oext html to generate html? – Chris Jul 21 '10 at 17:08
  • @Chris `cheetah fill a.tmpl` Should be sufficient to create a.html – Anycorn Jul 21 '10 at 17:34
  • @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 Jul 22 '10 at 14:53