Some of the information here may be outdated, please check the book instead

web2py controller automatically export some variables to the layout (reponse.title, response.keywords, response.description, response.flash, response.flash, and you can define your own). Here is how you can create your own layout.html file.

  • find a page layout that you like
  • make sure it released under some open source artistic license
  • give a name to it ('layoutsleek001')
  • create a folder under static called layoutsleek001 and move all the static files for the layout in there
  • save the layout under views as layout_sleel001.html
  • edit layoutsleek001.html and use {{=URL(r=request,c='static',f='layoutsleek001/whatever.css')}} to include the static files
  • edit layoutsleek001.html and make sure it has the following structure:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "">
<html xmlns="" xml:lang="en" lang="en">
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  <meta name="keywords" content="{{=response.keywords}}" />
  <meta name="description" content="{{=response.description}}" />
  <title>{{=response.title if response.title else request.application)}}</title>
  <link href="{{=URL(r=request,c='static',f='style.css')}}" rel="stylesheet" type="text/css"/> 
  {{include 'web2py_ajax.html'}}

<h1>Here goes the header, followed by the menu</h1>

<div id="menu">
  {{for _name,_active,_link in}}
    <li><a href="{{=_link}}" class="{{='active' if _active else 'inactive'}}">{{=_name}}</a></li>

<h1>Here goes the flash message</h1>

{{if response.flash:}}<div id="flash">{{=response.flash}}</div>{{pass}}

<h1>Here goes the main (the view that extends this one)</h1>


<h1>... and here the footer</h1> 

© 2008-2010 by Massimo Di Pierro - All rights reserved - Powered by web2py - design derived from a theme by the earlybird
The content of this book is released under the Artistic License 2.0 - Modified content cannot be reproduced.