Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Multi-part template issue with Jinja2
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Alan Harris-Reid  
View profile  
 More options Jun 14 2010, 7:38 pm
From: Alan Harris-Reid <aharrisr...@googlemail.com>
Date: Mon, 14 Jun 2010 16:38:20 -0700 (PDT)
Local: Mon, Jun 14 2010 7:38 pm
Subject: Multi-part template issue with Jinja2

Hi,

When creating templates I typically have 3 separate parts (header,
body, footer) which I combine to pass a singe string to the web-server
(CherryPy in this case).

My first approach is as follows...

   from jinja2 import Environment, FileSystemLoader
   env  = Environment(loader=FileSystemLoader(''))

   tmpl = env.get_template('Body.html')
   page_body = tmpl.render()

   tmpl = env.get_template('Header.html')
   page_header = tmpl.render()

   tmpl = env.get_template('Footer.html')
   page_footer = tmpl.render()

   page_code = page_header + page_body + page_footer

but this contains repetitious code, so my next approach is...

def render_template(html_file):
    from jinja2 import Environment, FileSystemLoader
    env  = Environment(loader=FileSystemLoader(''))
    tmpl = env.get_template(html_file)
    return tmpl.render()

page_header = render_template('Header.html')
page_body   = render_template('Body.html')
page_footer = render_template('Footer.html)

However, this means that each part is created in its own environment -
can that be a problem?  Are there any other downsides to this
approach?

I have chosen the 3-part approach over the child-template approach
because I think it may be more flexible (and easier to follow), but I
might be wrong.  Anyone like to convince me that using header, body
and footer blocks might be better?

Any advice would be appreciated.
Alan


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ali Afshar  
View profile  
 More options Jun 15 2010, 2:48 am
From: Ali Afshar <aafs...@gmail.com>
Date: Tue, 15 Jun 2010 07:48:42 +0100
Local: Tues, Jun 15 2010 2:48 am
Subject: Re: Multi-part template issue with Jinja2
On 15 Jun 2010, at 00:38, Alan Harris-Reid  

<aharrisr...@googlemail.com> wrote:
> Anyone like to convince me that using header, body
> and footer blocks might be better?

It may or may not be "better" but it is certainly more pleasant for  
the developer.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Alan Harris-Reid  
View profile  
 More options Jun 16 2010, 7:01 am
From: Alan Harris-Reid <aharrisr...@googlemail.com>
Date: Wed, 16 Jun 2010 04:01:30 -0700 (PDT)
Local: Wed, Jun 16 2010 7:01 am
Subject: Re: Multi-part template issue with Jinja2
Thanks for the reply Ali - looks like what is best for us developers
will win the day!

Alan

On Jun 15, 7:48 am, Ali Afshar <aafs...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »