Template-engine

Discussion in 'Python' started by =?ISO-8859-1?Q?Jan-Erik_Meyer-L=FCtgens?=, Nov 5, 2003.

  1. Miika Keskinen wrote:
    > 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.
    >

    Try Cheetah: http://www.cheetahtemplate.org/

    <HTML>
    <HEAD><TITLE>$title</TITLE></HEAD>
    <BODY>

    <TABLE>
    #for $client in $clients
    <TR>
    <TD>$client.surname, $client.firstname</TD>
    <TD><A HREF="mailto:$client.email">$client.email</A></TD>
    </TR>
    #end for
    </TABLE>

    </BODY>
    </HTML>

    ------------------------------------------------------
    from Cheetah.Template 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', ''),
    Client('Keskinen', 'Miika', ''),
    ]

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

    --
    Jan-Erik
     
    =?ISO-8859-1?Q?Jan-Erik_Meyer-L=FCtgens?=, Nov 5, 2003
    #1
    1. Advertising

  2. 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
     
    Miika Keskinen, Nov 5, 2003
    #2
    1. Advertising

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

    Thomas

    "Miika Keskinen" <> wrote in message
    news:p...
    > 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
     
    Thomas Weholt, Nov 5, 2003
    #3
  4. Am Wed, 05 Nov 2003 14:24:00 +0100 schrieb Jan-Erik Meyer-Lütgens:

    > Miika Keskinen wrote:
    >> 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.
    >>

    > Try Cheetah: http://www.cheetahtemplate.org/


    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
     
    Thomas Guettler, Nov 5, 2003
    #4
  5. 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 :)

    > Or you can try SimpleTal/es, available at http://www.owlfish.com
    >
    > Thomas
    >
    > "Miika Keskinen" <> wrote in message
    > news:p...
    >> 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.
     
    Miika Keskinen, Nov 5, 2003
    #5
  6. Miika Keskinen wrote:

    > 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.


    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:

    http://www.alcyone.com/software/empy/

    --
    Erik Max Francis && && 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
     
    Erik Max Francis, Nov 5, 2003
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?SmViQnVzaGVsbA==?=

    Is ASP Validator Regex Engine Same As VS2003 Find Regex Engine?

    =?Utf-8?B?SmViQnVzaGVsbA==?=, Oct 22, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    723
    =?Utf-8?B?SmViQnVzaGVsbA==?=
    Oct 22, 2005
  2. Chris Theis
    Replies:
    2
    Views:
    486
    Chris Theis
    Jul 24, 2003
  3. tom_usenet
    Replies:
    0
    Views:
    548
    tom_usenet
    Jul 24, 2003
  4. Replies:
    1
    Views:
    384
    Sybren Stuvel
    Apr 10, 2006
  5. Sasha
    Replies:
    3
    Views:
    605
    Sasha
    May 22, 2007
Loading...

Share This Page