[albatross-users] al-for and Template frustration and confusion
Sheila King
sheila at thinkspot.net
Fri Jun 20 17:31:36 EST 2003
Oh, I'm having a bit of fun today trying to work on templates. Or, not-fun,
rather.
I have a navigation bar with tabs for may application, and it appears in
every page, and I finally got to the point where I wanted to make it into a
macro. The navbar has two different views, depending on whether the client
is logged in (authenticated) or not (anonymous).
And the number of tabs is different in the two versions.
So, a macro with an al-for seemed like the best idea for this.
My understanding of the al-for iteration is
<al-for iter="i" expr="iterobj">
blah blah blah
</al-for>
that iterobj, as shown above, must be some sort of object over which one
can iterate. A list-type object should fit the bill here, yes? And then "i"
is one object in the iterobj data-structure.
Well, I have no idea why the following is failing...and I have tried a
number of things, none of which has worked, but this last attempt it seemed
to me SHOULD.
Here is a portion of my macro, with an ** at the beginning of the problem
line:
-----------------------------------------
<al-macro name="tabbed_navbar">
<table width="100%" cellpadding="0" cellspacing="0">
<tr align="left">
<al-if expr="_authstatus == 'auth'">
<al-exec expr="
tabnames = ['Main', 'Contact Info', 'Billing', 'Services']
tablinks = ['main', 'contactinfo', 'billing', 'services']
tabiter = range(4)
">
<al-else>
<al-exec expr="
tabnames = ['Login', 'Create Login', 'Lost Password']
tablinks = ['login', 'createlogin', 'lostpassword']
tabiter = range(3)
">
</al-if>
<al-for iter="i" expr="tabiter">
**<al-exec expr="
import os
linkurl = '/'.join(os.environ['SCRIPT_NAME'], tablinks[i])
">
...rest of macro omitted...
----------------------------------------------
Now the line
**<al-exec expr="
is where the error message occurs (obviously, the ** is not present in the
actual copy which I am running).
I am getting a parse error which essentially tells me:
"TypeError: sequence index must be integer"
The problem as far as I can see, is actually occurring two lines below,
where I use the following expression:
tablinks[i]
The "i" being used as an index on tablinks is for some reason not being
interpreted to be an integer.
How it could not be an integer is beyond me. I have constructed
numtabs = range(4)
which is certainly a list in which each item is an integer. If I iterate
over such a list, each item in the list must be an integer????
Well, I've been trying for a couple of hours now to solve this problem on
this one line. If there is something really stupid I'm doing here, I sure
would like to know. :/
--
Sheila King
http://www.thinkspot.net/sheila/
http://www.k12groups.org
More information about the Albatross-users
mailing list