| 36 | |
| 37 | This example shows how to execute a myghty template and pass the result to django template :) |
| 38 | {{{ |
| 39 | from django.shortcuts import render_to_response |
| 40 | import myghty.interp as interp |
| 41 | |
| 42 | interpreter = interp.Interpreter( |
| 43 | data_dir = './cache', # path to cache dir |
| 44 | component_root = '/path/to/myghty/templates', |
| 45 | ) |
| 46 | |
| 47 | class AFile(object): |
| 48 | """I'm a file :) from http://blog.zabiello.com""" |
| 49 | __content = '' |
| 50 | def write(self, txt): |
| 51 | self.__content += txt |
| 52 | def read(self): |
| 53 | return self.__content |
| 54 | |
| 55 | def myview(request): |
| 56 | file = AFile() |
| 57 | #execute a template |
| 58 | interpreter.execute('mytemplate.myt', out_buffer = file) |
| 59 | # show it via django template |
| 60 | return render_to_response('index.html', {'content': file.read()}) |
| 61 | }}} |