Skip to content

Dan-in-CA/templator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Templator

Simple, elegant Python based web templating (part of web.py). If you are familiar with Python, there is no new syntax to learn.
This is a stand-alone version of templator.

Usage

Clone the templaltor package into your project and add:

from templator import template

Then add e.g.:

template_globals = {  
    "str": str,  
    "json": json,  
    "time": time,  
    "my_function": my_function, #  you can pass your own functions to templator.  
}

Then add e.g.:

page_render = template.render("<templates folder>", globals=template_globals, [base="page_base"])

Then, for example, in cherrypy:

class My_project(object):
    """
    Base class for project pages
    """

    @cherrypy.expose
    def my_page(self, [param-1]): 
        [param-2 = "some text"]
        [param-3 = some_value]
        return str(page_render.my_page([param-1, param-2, param-3, other_var, etc])   
        # my_page == template file.
        # be sure to return a string. 

See the web.py templator documentation for details on setting up a template file.

You can read the documentation at:

https://webpy.readthedocs.io/en/latest/templating.html

About

A simple, elegant Python based web templating engine (part of web.py).

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages