Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make multiple web2py apps use the same layout.html?

Tags:

python

css

web2py

I have three applications, but I want them to use the same layout.html and css. Is there any way to achieve this?

EDIT:

I put the static folder and layout.html etc in /common/ under the web2py root.

Here's what I did in the model:

import os
global web2py_path
web2py_path = os.environ.get('web2py_path', os.getcwd())
session.layout_path = web2py_path + '/common/layout.html'
print 'session.layout_path = ' + session.layout_path

Then in the views:

{{extend session.layout_path}}

EDIT 2:

Regarding the comment below about compiling, I decided to put the 'common' folder into '/applications/' and place the static folder (css, images) inside the 'common' folder like a regular app. I then placed the layout.html into the root of 'common'. Then from another app's view, I used:

{{extend '../../common/layout.html'}}

Which referenced the layout.html from the common app. This layout.html file then referenced the files in the static folder within 'common' using:

{{=URL('common','static','css','style.css')}}

As you would for a regular application.

like image 813
Aram Kocharyan Avatar asked Sep 12 '11 23:09

Aram Kocharyan


1 Answers

in the root of your web2py folder create a new folder called 'templates'

/web2py/templates

put your layout.html there.

now in your views do:

{{extend 'path/to/web2py/templates/layout.html'}}
like image 130
Bruno Rocha - rochacbruno Avatar answered Sep 23 '22 18:09

Bruno Rocha - rochacbruno