Conceptually, this is the same as giving any module to access the
web2py helpers...you will need to make them available within the
namespace.  I did a quick test:

>>> content = "{{from gluon.html import *}}{{=A('hello world')}}"
>>> render(content=content)
'<a>hello world</a>'

So it works!  Other things you might need are:

from gluon.http import *
from gluon.validators import *
from gluon.sqlhtml import *

As with the old local_import, if you want request, session, cache, T,
db(s) they will need to be passed in the context.  For example:

context.db = db
context.request = request

Hope that clarifies it for you.


On Nov 2, 3:25 pm, lucas <sjluk...@gmail.com> wrote:
> ok, i feel like i am on the right path, getting hot.  i have this
> sample code to break it down,
>
>     q = """<i>ok dude, italic text.</i><br />
>     <b>this is plain but bold text.</b><br />
>     {{=A('web2py code', _href=URL('http://fscj.edu'))}}"""
>     from gluon.template import render
>     from gluon.storage import Storage
>     context = Storage()
>     q4 = render(content=q, context=context)
>
> or more simpler
>
>     q = """<i>ok dude, italic text.</i><br />
>     <b>this is plain but bold text.</b><br />
>     {{=A('web2py code', _href=URL('http://fscj.edu'))}}"""
>     from gluon.template import render
>     q4 = render(content=q)
>
> i get the same error which ends in:
>
> File "/opt/web-apps/web2py/gluon/template.py", line 916, in render
>     exec(code) in context
>   File "<string>", line 2, in <module>
> NameError: name 'A' is not defined
>
> make sense?  suggestions, please?  lucas

Reply via email to