How do I include dynamic page content in a template?

I need to include dynamic page content in my template. Let's say I have a left pane that dynamically passes data through a view. Now I have to include this left panel in all of my pages, but I don't want to duplicate code for all pages. Is there a way I can write one script and include it in all of my templates to display the left pane on all my pages?

Thanks in advance.

+2


a source to share


1 answer


What you are trying to achieve is directly supported in pretty much every templating language I know of. I would highly recommend using one of the many good Python options:

If you've used Genshi (the default templating language in TurboGears web app), what you want to do is 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

only needs to be defined once and reused on any other page.

0


a source







All Articles