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

@foreach returning "TypeError: undefined is not a function" #92

Open
DakuTree opened this issue Sep 19, 2015 · 1 comment
Open

@foreach returning "TypeError: undefined is not a function" #92

DakuTree opened this issue Sep 19, 2015 · 1 comment

Comments

@DakuTree
Copy link

Have had trouble trying to get @foreach to work. Nearly every variation I try seems to return the error.

From what I can tell, this seems to be caused by @foreach assuming the array/object has been stringified before being passed to it. If a array/object is passed normally, it fails when trying to do a .match().
The README makes no mention that this needs to be done beforehand either...

Example:

var pp = require('preprocess'),
    input = "<!-- @foreach $ITEM in LIST -->$ITEM<!-- @endfor -->";

pp.preprocess(input, {LIST: ['a', 'b', 'c'].toString()}); //returns abc

pp.preprocess(input, {LIST: ['a', 'b', 'c']}); //returns error || TypeError: undefined is not a function
@orionstein
Copy link
Contributor

This is more if an issue with the way preprocess handles variables.

Preprocess was designed to work with environment variables - every value is assumed to be a string. It does not handle raw JS data types currently, as you could not store one in an environment variable - you would need to store the stringified version to reference.

This could be fixed, but would need to think how it fits in with the rest of the intended function.

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

No branches or pull requests

2 participants