pyRazor icon indicating copy to clipboard operation
pyRazor copied to clipboard

Usage of local variables in the template

Open denis-itskovich opened this issue 9 years ago • 2 comments

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?

denis-itskovich avatar Jun 15 '15 13:06 denis-itskovich

Probably a bit late now but you could probably do

@: a = 1 @a

Creating inline support would need to be added.

luscoma avatar Jan 14 '18 05:01 luscoma

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.

Yeganloo avatar Jan 19 '18 08:01 Yeganloo