wiki:DeveloperGuidelines/Templates/CustomPages

Version 5 (modified by Fran Boon, 12 years ago) ( diff )

--

Custom Pages

Sahana Eden supports custom Pages as part of it's overall Templates system.

This allows customisation of:

  • Home page
  • Totally new pages

Custom pages are defined within the templates folder to reduce issues with merging.

NOTE: This is still a work-in-progress: the details may change...

Home Page

The web server is normally configured to redirect requests to:

http://host.domain

to:

http://host.domain/application/default/index

Which maps to controllers/default.py & the index() function therein.

The default application & controller can be easily edited in web2py/routes.py or within the web server configuration, however editing the default function might cause problems for other Sahana modules.

Sahana Eden is designed to check for the presence of a custom template and, if one is configured, then it attempts to load:

/private/templates/<template>/controllers.py

& then run the index() function inside there instead.

Notes

  • You must have an __init__.py in your template folder for this to work (it can be empty).
  • Unlike normal controllers, the scope this function is run in will start empty, so import what you need
  • If a custom View template is passed in from the Template folder then this will need to be provided as a File not a String to work in compiled mode:
    import os
    from gluon import current
    response = current.response
    path = os.path.join(current.request.folder, "private", "templates",
                        response.s3.theme, "views", "index.html")
    try:
       # Pass view as file not str to work in compiled mode
       response.view = open(path, "rb")
    except IOError:
       from gluon.http import HTTP
       raise HTTP("404", "Unable to open Custom View: %s" % path)
    

Custom Page

If a URL is specified like:

http://host.domain/application/default/index/<custompage>

The this alternate page will attempt to be loaded using the custompage() function in:

/private/templates/<template>/controllers.py

See Also

Note: See TracWiki for help on using the wiki.