pyRazor
pyRazor copied to clipboard
Usage of local variables in the template
Can local variables be defined and used in the template?
I tried to use template as simple as following:
@a = 1
@a
and expected that the produced output will be 1
, but it failed with the error: NameError: global name 'a' is not defined
Locally, I added a unit test, reproducing this issue:
def testSimpleLocalVariable(self):
self.assertEquals("1", pyrazor.Render("@a=1\n@a\n"))
Am I missing something?
Probably a bit late now but you could probably do
@: a = 1 @a
Creating inline support would need to be added.
The usage is wrong!
when you wrote @a = 1
it's equal to @(a) = 1
.
"= 1" is text and "a" is a local variable.
what you actually needs is @(a = 1)
and pyrazor do not support parenthesis yet.