代码之家  ›  专栏  ›  技术社区  ›  Chris Brandon

寻找一个预处理器来填充静态文件

  •  2
  • Chris Brandon  · 技术社区  · 14 年前

    index.html.模板:

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

    body.html.模板:

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

    4
    

    把它变成这样:

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

    虽然这个例子是HTML,但我可能会在很多奇怪的地方使用类似的东西。我认为有很多预处理器在那里;有没有一个非常基本的方法适合这个任务?

    1 回复  |  直到 14 年前
        1
  •  2
  •   Anycorn    14 年前

    http://www.cheetahtemplate.org/

    它基本上是嵌入在模板中的python语句,所以您可以访问所有python功能。小例子:

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

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

    此链接文档包括: http://www.cheetahtemplate.org/docs/users_guide_html/users_guide.html#SECTION000860000000000000000