[albatross-users] Re: al-macro and expr
Gabriel Cooper
gabriel.cooper at mediapulse.com
Thu Apr 8 00:44:43 EST 2004
Junk wrote:
> Hello Again,
>
> I find myself trying to do this over and over again in albatross (for
> example):
>
> <al-expand name="formlabel">firstName</al-expand>
>
> <al-macro name="formlabel">
> <al-if expr="custhandle.handlerErrors['<al-usearg>']">
> <font color="red"><al-usearg></font>
> <al-else><al-usearg></al-else>
> </al-if>
> </al-macro>
> [...]
The only way that I know of with the current Albatross release is to
assign variables instead of using the usearg, like so:
<al-exec expr="myargument = 'hello'">
<al-expand name="formlabel">
[....]
<al-macro name="formlabel">
<al-if expr="myargument == 'hello'>
do stuff
<al-else>
do other stuff
</al-if>
</al-macro>
This works because the variables you create before calling the macro are
within scope. The reason /not/ to do this is that the possibility for
you to overwrite your variables exists if you're not careful. For example:
def page_display(...):
ctx.locals.myargument = "let's use this in the body!"
self.page = "mypage.html"
[...]
<al-exec expr="myargument = 'hello'">
<al-expand name="formlabel">
[...]
(here we have the body where I wanted to print 'myargument':)
<al-value expr="myargument">
(which of course prints, as it should, "hello" and not "let's use this
in the body!". This is of course obvious, however if you're not careful
this can happen to you easily, especially if you have a tendency to name
like variables the same way every time.
There was some discussion on fixing this in albatross by letting you
actually manipulate the arguments, a la:
<al-macro name="formlabel">
<al-if expr="_args['myargument'] == 'hello'">
...
but to my knowledge no movement has been made for this.
Gabriel.
More information about the Albatross-users
mailing list