You can use the render() function:

import os
from gluon.template import render
mytext = cache.ram('mytext',
                   lambda: render(filename=os.path.join(request.folder, 
'path', 'to', 'template.html')),
                   time_expire=3600)

If the template contains any {{include ...}} directives, then you must also 
provide a "path" argument to render() specifying the file system path where 
any included files can be found. render() also takes a dictionary-like 
"context" argument and will render the template in the environment of that 
context. If you need the entire web2py environment available in the 
template, then set context=globals().

render(filename=os.path.join(request.folder, 'path', 'to', 'template.html'),
       path=os.path.join(request.folder, 'path', 'to', 'included', 
'templates')
       context=globals())

Anthony

On Thursday, November 7, 2013 9:49:14 PM UTC-5, Scott Hunter wrote:
>
> Is it possible to use a view to generate a string?  In this particular 
> case, I want to generate a snippet of HTML & cache it away.  I suppose this 
> could be done using straight python & helpers, but a view seems so much 
> more natural.
>
> - Scott
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to