[albatross-users] Confused over name spaces
Sheila King
sheila at thinkspot.net
Sat Sep 13 09:18:40 EST 2003
Name spaces seem to be one of the most confusing things for me in using
Albatross.
Mind you, I've found some work arounds for the issue I'm about to present,
but they seemed particularly inelegant to me and I did not like them.
I do not see why the following code produces an error. :\
Here is the template file:
---------(begin test.html)--------------
<al-macro name="mymacro">
<al-exec expr="""import time
now = time.localtime()
""" />
<al-value expr="str(now)" />
</al-macro>
<html>
<head><title>Test</title></head>
<body>
<al-expand name="mymacro" />
</body>
</html>
---------(end test.html)----------------
Here is the page module:
---------(begin test.py)----------------
import time
def page_process(ctx):
pass
def page_display(ctx):
ctx.run_template("test.html")
----------(end test.py)-----------------
Here is the essential error message (much traceback removed):
File "./blog/test.html", line 6, in al-value
<al-value expr="str(now)" />
NameError: name 'now' is not defined
I'm just wondering why, when I have define "now" one tag prior to invoking
it, that Albatross claims to have no idea what "now" is when I invoke it on
line 6 of the template file.
This example from the documentation
http://object-craft.com.au/projects/albatross/albatross/tag-exec-expr.html
certainly leads me to think I should be able to do this. In the linked
example, "results" is a list defined in an al-exec tag, and then
immediately following is an al-for tag that uses "results".
The only way around this type of thing that I have seen, is to define the
desired value (in my example this would be the value "now") within the page
module, such as
ctx.locals.now = time.localtime()
However, I don't want to do this because I am planning on using a
particular macro repeatedly wherever I like, and I don't want to have to
set the values in each page module before calling this macro. I want the
macro to handle it for me.
Any ideas?
--
Sheila King
http://www.thinkspot.net/sheila/
http://www.k12groups.org
More information about the Albatross-users
mailing list