PyMeld for html templates?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sean Schertell

    PyMeld for html templates?

    I'm trying to decide which template system to get married to. I think
    I've narrowed it down to PyMeld, Cheetah, or Jinja but leaning
    heavily toward PyMeld because I love the idea that your templates are
    *totally* clean and that get manipulated from behind the scenes. This
    seems to be elegantly inline with the Sacred Creed of separation of
    logic from presentation.

    Of course I'm going to try them all but I wonder if anyone has any
    thoughts on PyMeld as a template system for churning out general
    websites?

    One important consideration is that even though PyMeld itself doesn't
    support template inheritance so far as I know, I'll need to
    accomplish that somehow. I want for a URI request to mysite.com/info
    to pull in a layout.html template which will in turn be populated by
    the info.html template. I've already got the URI mapping stuff
    sorted. But how about PyMeld, any ideas on how to do it or whether it
    will even work as I've described?

    Thanks!

    Sean


    :::: DataFly.Net ::::
    Complete Web Services


  • Bruno Desthuilliers

    #2
    Re: PyMeld for html templates?

    Sean Schertell a écrit :
    I'm trying to decide which template system to get married to. I think
    I've narrowed it down to PyMeld, Cheetah, or Jinja but leaning heavily
    toward PyMeld because I love the idea that your templates are *totally*
    clean and that get manipulated from behind the scenes. This seems to be
    elegantly inline with the Sacred Creed of separation of logic from
    presentation.
    "separating logic from presentation" is often misunderstood. It should
    really read "separating application logic from presentation logic", not
    "separating presentation logic from html code".
    Of course I'm going to try them all
    The don't forget to have a look at Genshi and Mako too.

    My 2 cents...

    Comment

    • metaperl

      #3
      Re: PyMeld for html templates?


      Sean Schertell wrote:

      >
      Of course I'm going to try them all but I wonder if anyone has any
      thoughts on PyMeld as a template system for churning out general
      websites?
      >
      meld3 evolved from pymeld. I use meld3 -

      this whole style of templating is known as push-style (coined by
      Terence Parr). Most systems are pull-style.

      sorted. But how about PyMeld, any ideas on how to do it or whether it
      will even work as I've described?
      >
      the meat and bread problem: each page has meat and you want to wrap it
      with some standard bread. it's a basic tree rewrite and since meld3
      uses ElementTree underneath, it is a piece of cake.

      Comment

      • Richie Hindle

        #4
        Re: PyMeld for html templates?

        [Sean]
        I wonder if anyone has any thoughts on PyMeld as a template
        system for churning out general websites?
        I'm doing that (but then I would be wouldn't I? 8-)
        http://www.mandant.net is an example - the content of each page comes
        from a file containing just the content, the layout and sidebar are
        defined in a template HTML file, and the navigation is built by a
        Python script. All that is pulled together using PyMeld into a set of
        HTML files and deployed to the web server (there's no need to it on the
        fly for that site, but you certainly could).
        I want for a URI request to mysite.com/info
        to pull in a layout.html template which will in turn be populated by
        the info.html template. [...] how about PyMeld, any ideas on how
        to do it or whether it will even work as I've described?
        You'd do something like this:

        from PyMeld import Meld

        LAYOUT = """<html><head> <title id='title'>The Title</title></head>
        <body><div id='info'>The page information goes here.</div>
        <p id='footer>Copy right Me 2007.</p></body></html>"""

        INFO = """<html><head> <title id='title'>The real title</title></head>
        <body id='info'><p>He re is the info, which would in the real world
        be read from a file.</p></body></html>"""

        page = Meld(LAYOUT)
        info = Meld(INFO)
        page.title = info.title._con tent
        page.info = info.info._cont ent
        print page

        Is that the sort of thing you had in mind?

        --
        Richie Hindle
        richie@entrian. com

        Comment

        • Sean Schertell

          #5
          Re: PyMeld for html templates?

          Thanks Richie! That's exactly the reply I was hoping for.

          Hooray!

          Sean



          On Jan 20, 2007, at 9:50 PM, Richie Hindle wrote:
          Hi Sean,
          >
          >Thanks Richie -- but actually, what I had in mind was slightly
          >different. I want for my CONTENT pages to only contain the content.
          >So to modify your example:
          >>
          >LAYOUT = """<html><head> <title id='title'>The Title</title></head>
          ><body><div id='info'>The page information goes here.</div>
          ><p id='footer>Copy right Me 2007.</p></body></html>"""
          >>
          >INFO = """<div id='info'><p>He re is the info, which would in the real
          >world
          >be read from a file.</p></div>"""
          >>
          >Can I do this just as easily?
          >
          Yes, of course, just the same way:
          >
          from PyMeld import Meld
          >
          LAYOUT = """<html><head> <title id='title'>The Title</title></head>
          <body><div id='info'>The page information goes here.</div>
          <p id='footer>Copy right Me 2007.</p></body></html>"""
          >
          INFO = """<div id='info'><p>He re is the info, which would in the real
          world be read from a file.</p></div>"""
          >
          page = Meld(LAYOUT)
          info = Meld(INFO)
          page.info = info.info._cont ent
          print page
          >
          There's nothing that says a Meld has to be a complete HTML document.
          >
          >One other unrelated question... Let's say I have a table with a
          >template row with id="myRow". I want to use PyMeld to clone that row
          >n number of times (depending on database results). So here's my
          >stoopid question: Does that mean that my XHTML will contain n rows
          >all with the same id="myRow" thereby making my XHTML invalid?
          >
          Yes, it does, but you can simply delete the 'id' attributes from
          the rows,
          with `del row.id`, before adding them back into the document.
          >
          --
          Richie Hindle
          richie@entrian. com

          Comment

          • Sean Schertell

            #6
            Re: PyMeld for html templates?

            I'm trying to get PyMeld happening but I'm a bit stumped as to how to
            make it work with mod_python.

            The pymeld docs show examples only for the Python command line
            interpreter and show using the print statement to output stuff. But
            using mod_python.apac he, I think you need to use req.write(somet hing)
            format. And of course, this fails when you feed it output from Meld.

            Any tips?

            Sean



            On Jan 20, 2007, at 6:18 AM, Richie Hindle wrote:
            [Sean]
            >I wonder if anyone has any thoughts on PyMeld as a template
            >system for churning out general websites?
            >
            I'm doing that (but then I would be wouldn't I? 8-)
            http://www.mandant.net is an example - the content of each page comes
            from a file containing just the content, the layout and sidebar are
            defined in a template HTML file, and the navigation is built by a
            Python script. All that is pulled together using PyMeld into a set of
            HTML files and deployed to the web server (there's no need to it on
            the
            fly for that site, but you certainly could).
            >
            >I want for a URI request to mysite.com/info
            >to pull in a layout.html template which will in turn be populated by
            >the info.html template. [...] how about PyMeld, any ideas on how
            >to do it or whether it will even work as I've described?
            >
            You'd do something like this:
            >
            from PyMeld import Meld
            >
            LAYOUT = """<html><head> <title id='title'>The Title</title></head>
            <body><div id='info'>The page information goes here.</div>
            <p id='footer>Copy right Me 2007.</p></body></html>"""
            >
            INFO = """<html><head> <title id='title'>The real title</title></head>
            <body id='info'><p>He re is the info, which would in the real world
            be read from a file.</p></body></html>"""
            >
            page = Meld(LAYOUT)
            info = Meld(INFO)
            page.title = info.title._con tent
            page.info = info.info._cont ent
            print page
            >
            Is that the sort of thing you had in mind?
            >
            --
            Richie Hindle
            richie@entrian. com
            >
            --
            http://mail.python.org/mailman/listinfo/python-list

            Comment

            • Richie Hindle

              #7
              Re: PyMeld for html templates?

              [Sean]
              The pymeld docs show examples only for the Python command line
              interpreter and show using the print statement to output stuff. But
              using mod_python.apac he, I think you need to use req.write(somet hing)
              format. And of course, this fails when you feed it output from Meld.
              req.write(str(m eld)) ?

              --
              Richie Hindle
              richie@entrian. com

              Comment

              Working...