Skip to navigation

Edit Templates and Layouts

Pyplate uses HTML templates to fill in parts of each web page.  These templates are snippets of HTML stored in the template directory (by default this is in /usr/share/pyplate/templates), and they're used to fill in the page banner, and footer.  You can edit these templates by going to your site's Admin area and clicking on 'Site Settings'.  

The head section

There is a template file that gets embedded in the head section of each page.  This can contain things like meta data, links to CSS files, and Javascript code.  If you want to use Google Analytics to track the number of visitors on your site, you need to paste your Google tracking code in the head section.

The Banner and Footer Templates

The banner needs to contain an HTML div with a class attribute "banner".  Inside the div, you can add a title wrapped in h1 tags, followed by a subtitle for your site wrapped in h2 tags.  If you want you can go further than this and have several divs inside the banner.  In this site, I've used the banner div to contain one div for the left side of the banner, and another div for the contents of the right side of the banner.  

The footer field can be used to create a page footer.  This field needs to contain an HTML div with the class attribute "footer".  Again this can contain more than one div if you wish.

The Navigation Bar

By default, the navigation bar is generated by Pyplate.  When Pyplate generates this part of the page, it accesses the database to get a list of all the top level categories in your site 

(categories whose parent is the root category), and prints links to those categories as an unordered list as follows:

<div class="navbar">
 <ul class="navmenu">
  <li><a href="/">Home</a></li>
  <li><a href="/overview/">Overview</a></li>
  <li><a href="/how-to/">How-To</a></li>
 </ul>
</div>

Sometimes you might want to use a handwritten navigation bar.  Using code in Pyplate to generate the navigation bar every time a page is served uses up quite a lot of CPU cycles.  It's faster to use a template file instead.  Another reason to use a template is that you might want to customize the navigation bar.  For example, if I wanted to include a link to another site in my navigation bar, I would just add another li tag containing a link like this:

<div class="navbar">
 <ul class="navmenu">
  <li><a href="/">Home</a></li>
  <li><a href="/overview/">Overview</a></li>
  <li><a href="/how-to/">How-To</a></li>
  <li><a href="http://some-other-site.com/">Some other site</a></li>
 </ul>
</div>

This code needs to be pasted into the navigation bar field on the Site Settings page.  The code in layouts.py needs to be modified so that Pyplate uses the navigation bar template instead of generating the navigation bar from the database.  On the Site Settings page, scroll down to the Layout field.  Scroll down until you see a function called getLayout, and look for the following line of code:

navbar=pyplate.get_navbar(dbase),

Comment out this line by putting a '#' symbol in front of it.  Add the following code:

navbar=pyplate.getFile(pyplate.getCMSRoot()+"/template/navbar.html"),

Don't forget the comma at the end of this line.  You need to make this change anywhere that you see a call to pyplate.get_navbar in getLayouts.

Share this page:

Follow me