include templates with variable names in bottle.py's template-engine

214 views
Skip to first unread message

jouz

unread,
Jan 14, 2010, 7:06:52 PM1/14/10
to bottlepy
Is there anything like this? Or could you make it working?:

% t = '/'.join(path)
% include ${t}

here, "path" is a list like ['home','bla','bla2'].

Thanks!

Marcel Hellkamp

unread,
Jan 15, 2010, 1:38:06 AM1/15/10
to bott...@googlegroups.com

The %include statement loads the subtemplate at compile time, so there
is no way to pass a dynamic name. But you can just use the
bottle.template() function to do the same with dynamic template names.

This should work:

from bottle import template
tpl = '''
% t = '/'.join(['home','bla','bla2'])
{{template(t)}}
'''
print template(tpl, template=template)

I hope that helped

jouz

unread,
Jan 15, 2010, 5:59:31 AM1/15/10
to bottlepy
Thank you for your reply!
I somehow couldn't make your code work, but it helped to find a
solution!
My code now looks like this:

% from bottle import template


% t = '/'.join(['home','bla','bla2'])

% templ = ''.join(template(t, template=template))

{{templ}}

Thanks again for your help and bottle.py :)

Reply all
Reply to author
Forward
0 new messages