Open mjordan opened 10 years ago
defined read var, example:
defined('abc')
Recommend return you dict via args, example:
template('test.html', **my_dict)
In template:
% if defined('id'):
<input type="hidden" name="id" value="{{ id }}" />
% end
Thanks a million, that worked. But the docs at http://bottlepy.org/docs/0.12/tutorial.html#templates and http://bottlepy.org/docs/0.12/stpl.html don't provide examples of this type of usage. I don't mind opening a pull request to update the docs.
All contributions are welcome!
Not sure that docs change makes sense - you're documenting a python language feature, not a bottle feature
I'm documenting how to use a python language feature in a bottle template. Not sure why that doesn't make sense.
Answering your original question:
% if 'id' in my_dict:
<input type="hidden" name="id" value="{{my_dict['id']}}" />
% end
@eric-wieser thanks, that was very helpful. I was totally lost since it seems that using the **ars method does not work with namespaces. My variables come from a .conf ini file with namespaces. However, the separator makes the variables not work. Using the "regular" approach solved that for me. Thanks!
I'm running 0.12.7 and have hit a problem. I'm wondering if anyone can explain why the following code doesn't work if my_dict['id'] is defined in the current template:
defined() is not returning True. I have confirmed that my_dict['id'] is getting passed to my template because I can output it in textfields in my form. If I replace my_dict['id'] with the name of a string variable, defined() does return True and the HTML is rendered as expected.
Possible bug, working as designed, or am I misunderstanding something?