Template-engine

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Miika Keskinen

    Template-engine

    Hi all

    I was in need for a simple template engine (like PEAR::IT.php) and didn't
    find any suitable. Yes, there is many templating engines available but
    most are far too complex or does implement some additional features in
    their syntax.

    So I created following and I'm asking comments - and yes I know there is
    couple not so pythonistic sides in code. Most of all accessing inner dict
    B straight. This is however first working version (started it hour ago)
    and I'm asking if any of you have something in mind that could help me
    making that better.

    This engine is non only for html ( in fact I don't use it for html but
    email-templates and some configuration-templates ).

    the beast can be found from http://users.utu.fi/mikrke/index.html
    (includes example how to use it)

    --
    Miika
  • Jan-Erik Meyer-Lütgens

    #2
    Re: Template-engine

    Miika Keskinen wrote:[color=blue]
    > Hi all
    >
    > I was in need for a simple template engine (like PEAR::IT.php) and didn't
    > find any suitable. Yes, there is many templating engines available but
    > most are far too complex or does implement some additional features in
    > their syntax.
    >[/color]
    Try Cheetah: http://www.cheetahtemplate.org/

    <HTML>
    <HEAD><TITLE>$t itle</TITLE></HEAD>
    <BODY>

    <TABLE>
    #for $client in $clients
    <TR>
    <TD>$client.sur name, $client.firstna me</TD>
    <TD><A HREF="mailto:$c lient.email">$c lient.email</A></TD>
    </TR>
    #end for
    </TABLE>

    </BODY>
    </HTML>

    ------------------------------------------------------
    from Cheetah.Templat e import Template

    class Client:
    def __init__(self, surname, firstname, email)
    self.surname = surname
    self.firstname = firstname
    self.email = email

    clients = [
    Client('Meyer-Lütgens', 'Jan-Erik', 'un@kown.de'),
    Client('Keskine n', 'Miika', 'un@known.fi'),
    ]

    tpl = Template(file=' path_to_tpl_fil e')
    tpl.title = 'The Title'
    tpl.clients = clients
    print tpl

    --
    Jan-Erik

    Comment

    • Thomas Weholt

      #3
      Re: Template-engine

      Or you can try SimpleTal/es, available at http://www.owlfish.com

      Thomas

      "Miika Keskinen" <miika.keskinen @utu.fi> wrote in message
      news:pan.2003.1 1.05.14.20.42.4 73860@utu.fi...[color=blue]
      > Hi all
      >
      > I was in need for a simple template engine (like PEAR::IT.php) and didn't
      > find any suitable. Yes, there is many templating engines available but
      > most are far too complex or does implement some additional features in
      > their syntax.
      >
      > So I created following and I'm asking comments - and yes I know there is
      > couple not so pythonistic sides in code. Most of all accessing inner dict
      > B straight. This is however first working version (started it hour ago)
      > and I'm asking if any of you have something in mind that could help me
      > making that better.
      >
      > This engine is non only for html ( in fact I don't use it for html but
      > email-templates and some configuration-templates ).
      >
      > the beast can be found from http://users.utu.fi/mikrke/index.html
      > (includes example how to use it)
      >
      > --
      > Miika[/color]


      Comment

      • Thomas Guettler

        #4
        Re: Template-engine

        Am Wed, 05 Nov 2003 14:24:00 +0100 schrieb Jan-Erik Meyer-Lütgens:
        [color=blue]
        > Miika Keskinen wrote:[color=green]
        >> Hi all
        >>
        >> I was in need for a simple template engine (like PEAR::IT.php) and didn't
        >> find any suitable. Yes, there is many templating engines available but
        >> most are far too complex or does implement some additional features in
        >> their syntax.
        >>[/color]
        > Try Cheetah: http://www.cheetahtemplate.org/[/color]

        try python:

        def foo(self):
        ret=[]
        ret.append(self .header())
        ret.append("""
        Time is too short to rewrite parsers <br>
        ...
        """)
        ret.append(self .footer())
        return ''.join(ret)

        thomas

        Comment

        • Miika Keskinen

          #5
          Re: Template-engine

          On Wed, 05 Nov 2003 16:48:40 +0100, Thomas Weholt wrote:

          Well. These all look very promising. At my situation (I have lot's of
          templates originally written for php/IT) amount of work needed for using
          them would be too much. (of course one could write down some regexp-beasts
          or parsers to automatically convert them - I'm not that one :)

          So currently I will stick on my implementation and for future projects
          it might well be showtime for chetah/simpleTal.

          btw. If my work is not useful to any other it might server well as
          newbie-example how to use re.sub :)
          [color=blue]
          > Or you can try SimpleTal/es, available at http://www.owlfish.com
          >
          > Thomas
          >
          > "Miika Keskinen" <miika.keskinen @utu.fi> wrote in message
          > news:pan.2003.1 1.05.14.20.42.4 73860@utu.fi...[color=green]
          >> Hi all
          >>
          >> I was in need for a simple template engine (like PEAR::IT.php) and didn't
          >> find any suitable. Yes, there is many templating engines available but
          >> most are far too complex or does implement some additional features in
          >> their syntax.[/color][/color]

          Comment

          • Erik Max Francis

            #6
            Re: Template-engine

            Miika Keskinen wrote:
            [color=blue]
            > I was in need for a simple template engine (like PEAR::IT.php) and
            > didn't
            > find any suitable. Yes, there is many templating engines available but
            > most are far too complex or does implement some additional features in
            > their syntax.[/color]

            EmPy has a lot of additional features, but they're all optional. Basic
            use of EmPy for templating is as lightweight, if not more, as your
            approach:



            --
            Erik Max Francis && max@alcyone.com && http://www.alcyone.com/max/
            __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
            / \ I just don't know why they're shooting at us.
            \__/ Capt. Benjamin "Hawkeye" Pierce

            Comment

            Working...