Open
Description
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:
% if defined(my_dict['id']):
<input type="hidden" name="id" value="{{my_dict['id']}}" />
% end
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?
Metadata
Metadata
Assignees
Labels
No labels
Activity
avelino commentedon Sep 17, 2014
defined read var, example:
Recommend return you dict via args, example:
In template:
http://bottlepy.org/docs/dev/stpl.html#stpl.defined
mjordan commentedon Sep 17, 2014
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.
avelino commentedon Sep 17, 2014
All contributions are welcome!
Addresses bottlepy#659.
eric-wieser commentedon Sep 23, 2014
Not sure that docs change makes sense - you're documenting a python language feature, not a bottle feature
mjordan commentedon Sep 24, 2014
I'm documenting how to use a python language feature in a bottle template. Not sure why that doesn't make sense.
Merge pull request #660 from mjordan/master
eric-wieser commentedon Dec 27, 2014
Answering your original question:
basbebe commentedon Feb 20, 2015
@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!