baryshev / ect

Fastest JavaScript template engine with embedded CoffeeScript syntax
http://ectjs.com
MIT License
626 stars 70 forks source link

Unable to use variables passed to extended template in base template #71

Closed ameyp closed 10 years ago

ameyp commented 10 years ago

Suppose that template 'layout.ect' extends template 'default.ect'. Any variables passed to a call to render with layout.ect appear as undefined for any usage in template default.ect

The example in the readme under "You may use JavaScript object as root." also fails with the following:

c:\Users\Amey\Developer\sample\node_modules\ect\lib\ect.js:384
            throw e;
                  ^
ReferenceError: title is not defined in layout on line 1
  at Object.__ectTemplate (<anonymous>:6:79)
  at Object.__ectTemplate (<anonymous>:23:34)
  at [object Object].TemplateContext.render (c:\Users\Amey\Developer\sample\node_modules\ect\lib\ect.js:372:31)
  at [object Object].render (c:\Users\Amey\Developer\sample\node_modules\ect\lib\ect.js:421:20)
  at Object.<anonymous> (c:\Users\Amey\Developer\sample\test.js:9:21)
  at Module._compile (module.js:456:26)
  at Object.Module._extensions..js (module.js:474:10)
  at Module.load (module.js:356:32)
  at Function.Module._load (module.js:312:12)
  at Function.Module.runMain (module.js:497:10)
  at startup (node.js:119:16)
  at node.js:906:3
baryshev commented 10 years ago

Thank you for report. There is a typo in example. Now fixed. All variables passed to templates need to be prefixed with @.

About your first question. Can you show code that represents error?

ameyp commented 10 years ago

I'm getting the same error with the changes you made in the README

Edit - Sorry, the README sample is working. I'll abstract my code into a case that's causing the error.

ameyp commented 10 years ago

Ok, I made the simplest example and it worked. There was a bug in my template, I was using a for loop variable with @ instead of using it directly. Sorry for the erroneous bug.