pythontemplatesrenderweb.py

How do I write custom renderers with web.py


Being new to python and web.py, I'm not sure if what I want is possible, but I'm trying to assign unique renderers for my templates so that my templates cant use a a specific file structure.

So I have: code.py

Main = web.template.render('templates/', globals=common_globals)
Section1 = web.template.render('templates/Section1/', globals=common_globals)

And later when referencing these,

This works:

class index:
def GET(self):
    vPage = '0'
    vLevel = '0'
    vSection = '0'
    return Main.Layout(vPage, vLevel, vSection)

But this doesn't:

class Section1:
def GET(self):
    vPage = '0'
    vLevel = '1'
    vSection = '1'
    return Section1.Layout(vPage, vLevel, vSection)

Any advice to whether or not this is possible or how it works would be lovely.


Solution

  • I found this unanswered in my questions.

    I believe the issue was in the Layout.html, anything but all zeroes wasn't working because the variables were defaulting to zero.

    Not sure what the exact version was when this was an issue, but working version of Layout.html is using something like:

    $def with (vPage, vLevel, vDivision)
    $:getNavigationHeader()
    

    Univeersal.py having

    def getNavigationHeader():
        vResult = ''
        
        vResult += '<h4>'
        vResult += 'Navigation'
        vResult += '</h4>'
        
        return vResult
    

    All methods have a similar pattern.