Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to pass a array of values to the template in the yeoman generator #1245

Closed
helxsz opened this issue Jun 4, 2020 · 2 comments
Closed
Labels
needs triage Awaiting triage

Comments

@helxsz
Copy link

helxsz commented Jun 4, 2020

I am using yeoman-generator, which I need to pass a array of value to the template file. for example I want to pass a array of text values to the template.

  install() {
      async app() {
         let array = ['abc','cde','efg'];
           this.fs.copyTpl(
            this.templatePath('base','/abc.ts'),
            this.destinationPath('example/abc.ts'),
            {'array':array}
          );         
      } // app 
  }// install 

in the .ts file, i define a variable which received the passed array.

public options = <%= array %> ; My expected result is

public options = ['abc','cde','efg'] ; however the resulted output is

public options = abc,cde,efg ;how would I resolve this problem ?

@helxsz helxsz added the needs triage Awaiting triage label Jun 4, 2020
@mshima
Copy link
Member

mshima commented Jun 4, 2020

public options = [<%= array.map(value => `'${value}'`).join(',') %>] ;
Please keep this repository for generator related issues only.
Post others questions to stackoverflow or the related project, in this case ejs.

@mshima mshima closed this as completed Jun 4, 2020
@helxsz
Copy link
Author

helxsz commented Jun 4, 2020

thanks @mshima

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage Awaiting triage
Projects
None yet
Development

No branches or pull requests

2 participants