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

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:

layoutsleek001.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <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'}}
</head>
<body>

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

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

<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>

{{include}}

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

</body>
</html>
© 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.