On Monday, June 20, 2011 9:54:16 PM UTC-4, rochacbruno wrote:
>
> On Mon, Jun 20, 2011 at 10:40 PM, Anthony <[email protected]> wrote:
>
>> {{include 'pat/to/file'}}
>>
>> Note, the template doesn't have to be purely static for the above to
>> work. Look at web2py_ajax.html, for example -- it is included in layout.html
>> but is not static.
>> Anthony
>>
>
> Your're right, but. the parsing will be executed before the inclusion, the
> destiny page will receive a formed html string to embed there, not a
> template to be parsed. so to share values needs to use globals.
>
I think the original template code is converted to pure Python before the
inclusion, but the Python isn't executed (and therefore converted into the
final parsed output) until all the extending and including is done. So, for
a given view, the entire tree (of extended and included views) is built out
before the Python is executed (the full tree is what is bytecode compiled).
So, you can do:
def index():
return dict(message='Hello', othermessage='Goodbye')
In index.html:
{{=message}}
{{include 'otherview.html'}}
In otherview.html:
{{=othermessage}}
And the resulting page will say:
Hello
Goodbye
Anthony