eco icon indicating copy to clipboard operation
eco copied to clipboard

Any intention to add an 'include' tag to enable nested templates?

Open stringfellow opened this issue 12 years ago • 6 comments

I've got a couple of cases where I have a template that I reuse within other templates and at the moment its a copy-paste job. Am I missing something? Is this a reasonable feature request?

stringfellow avatar Mar 09 '12 09:03 stringfellow

will this work for you ?

<%- eco.render(fs.readFileSync('someTemplate.eco'), @ ) %>

sircambridge avatar Mar 19 '12 06:03 sircambridge

Hmm, possibly. I'm using eco in spinejs and I don't think I have implicit access to the eco module within the template... But am probably missing something.

stringfellow avatar Mar 19 '12 10:03 stringfellow

You might be able to global.eco = require('eco') ?

Or pass the Eco reference into the context object, @eco = require('eco')

Gene Tsai Sent with Sparrow (http://www.sparrowmailapp.com/?sig)

On Monday, March 19, 2012 at 3:33 AM, Steve Pike wrote:

Hmm, possibly. I'm using eco in spinejs and I don't think I have implicit access to the eco module within the template... But am probably missing something.


Reply to this email directly or view it on GitHub: https://github.com/sstephenson/eco/issues/42#issuecomment-4570772

sircambridge avatar Mar 19 '12 19:03 sircambridge

I am compiling eco template using eco command-line and wondering the same thing -- how to nest templates?

trans avatar Apr 13 '12 14:04 trans

In my case, I'm sending the templates directly to the clients, and they all get stored in the "JST" variable (this is done automatically by Rails).

To nest a template then, I use:

<%- JST['template_name'](myVar: 1) %>

lagartoflojo avatar May 08 '12 19:05 lagartoflojo

@sircambridge I try this: pass to the outer template the eco, fs, and templateDir object, in the template I do this:

<%- @eco.render( @fs.readFileSync(@templateDir + '/Makefile_partial.eco'), @) %>

But I get an error, whatever the partial contains some string, nochting (empty) or a variable print:

Users/timaschew/project/node_modules/eco/lib/scanner.js:31
      this.source = source.replace(/\r\n?/g, "\n");
               ^
TypeError: Object  has no method 'replace'
  at new Scanner (/Users/timaschew/project/node_modules/eco/lib/scanner.js:31:28)
  at new Preprocessor (/Users/timaschew/project/node_modules/eco/lib/preprocessor.js:17:22)
  at module.exports.Preprocessor.preprocess (/Users/timaschew/project/node_modules/eco/lib/preprocessor.js:12:22)
  at exports.precompile.precompile (/Users/timaschew/project/node_modules/eco/lib/compiler.js:12:35)
  at exports.compile (/Users/timaschew/project/node_modules/eco/lib/compiler.js:19:38)
  at module.exports.eco (/Users/timaschew/project/node_modules/eco/lib/index.js:11:86)
  at Function.eco.render (/Users/timaschew/project/node_modules/eco/lib/index.js:26:13)
  at Object.eval (<anonymous>:74:27)
  at Object.eval (<anonymous>:106:8)
  at eval (<anonymous>:108:6)
  at Function.eco.render (/Users/timaschew/project/node_modules/eco/lib/index.js:26:25)
  at /Users/timaschew/project/tools/create_makefile.coffee:90:17, <js>:107:43
  at fs.js:266:14
  at Object.oncomplete (fs.js:107:15)

timaschew avatar Aug 16 '13 08:08 timaschew