tags:

views:

37

answers:

1

Hi All,

I have to include a dynamic page content into my template, Say I have a left panel which gets the data dynamically through a view. Now, I have to include this left panel into all my pages but I do not want to duplicate the code for all the pages. Is there any way, I can write a single script and include it in all my templates to display the left panel in all my pages?

Thanks in advance.

A: 

What you trying to achieve is directly supported in pretty much all template languages I know of. I would strongly recommend using one the many good choices for Python:

If you were using Genshi for example (the default template language in TurboGears web application framework) what you want to do would look something like this:

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:py="http://genshi.edgewall.org/"
      xmlns:xi="http://www.w3.org/2001/XInclude"
      py:strip="">
  <xi:include href="header.html" />
  <xi:include href="sidebar.html" />
  <xi:include href="footer.html" />

  <!-- The rest of your page goes here -->
<html>

header.html, sidebar.html and footer.html need only be defined once and reused in any other page.

Tendayi Mawushe
Thanks for your help Tendayi , your suggestion seems to work in case the contents are static i.e. for the html files. But in my case the the contents are generated dynamically as I mentioned and this would not work.
Ankit