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

Can't use key/index variable on each #112

Closed
fdorantesm opened this issue Feb 10, 2017 · 4 comments
Closed

Can't use key/index variable on each #112

fdorantesm opened this issue Feb 10, 2017 · 4 comments

Comments

@fdorantesm
Copy link

Hi, im trying to get index value on each but get:

Message: Use of undefined constant index - assumed 'index'

My code:

                colors = ["green","red","aqua","sky","blue"]
		each item,i in [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]
			p= colors[i]

I tried to create var using - var, - name and name = but i can't get it.

Is this possible?

@kylekatarnls
Copy link
Member

kylekatarnls commented Feb 10, 2017

The following code will works on default mode ('expressionLanguage' => 'auto' or 'expressionLanguage' => 'php' in options):

colors = ["green","red","aqua","sky","blue"]
each item in [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]
	p= $colors[$item]

Else you can do this on js expression mode:
The following code will works on default mode ('expressionLanguage' => 'js')

- var colors = ["green","red","aqua","sky","blue"]
each item in [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]
	p= colors[item]

Does it do the trick for you?

@fdorantesm
Copy link
Author

fdorantesm commented Feb 12, 2017

Fatal error appears after expression change:

Fatal error: Uncaught exception 'JsPhpize\Parser\Exception' with message 'Unexpected . in on line 1 near from "" .' in C:\localhost\htdocs\comercial\vendor\js-phpize\js-phpize\src\JsPhpize\Parser\TokenCrawler.php:40 Stack trace: #0 C:\localhost\htdocs\comercial\vendor\js-phpize\js-phpize\src\JsPhpize\Parser\Parser.php(322): JsPhpize\Parser\TokenCrawler->unexpected(Object(JsPhpize\Lexer\Token)) #1 C:\localhost\htdocs\comercial\vendor\js-phpize\js-phpize\src\JsPhpize\Parser\Parser.php(343): JsPhpize\Parser\Parser->parseInstructions(Object(JsPhpize\Nodes\Main)) #2 C:\localhost\htdocs\comercial\vendor\js-phpize\js-phpize\src\JsPhpize\Parser\Parser.php(351): JsPhpize\Parser\Parser->parseBlock(Object(JsPhpize\Nodes\Main)) #3 C:\localhost\htdocs\comercial\vendor\js-phpize\js-phpize\src\JsPhpize\JsPhpize.php(52): JsPhpize\Parser\Parser->parse() #4 C:\localhost\htdocs\comercial\vendor\js-phpize\js-phpize\src\JsPhpize\JsPhpize.php(86): JsPhpize\JsPhpize->compile('"" . '#' . "spe...', 'source.js') #5 [internal function]: JsPhpize\J in C:\localhost\htdocs\comercial\vendor\pug-php\pug\src\Jade\Compiler\Visitor.php on line 52

That appears in basic template:
doctype
html
head
title test
body

@kylekatarnls
Copy link
Member

Hi, can you give me the complete pug file with indent or try to reproduce the exception on http://pug-demo.herokuapp.com/

Thanks,

@kylekatarnls
Copy link
Member

As the last error you mention is not linked to the issue title and would probably be solved with last js-phpize release, I close this issue. Please open a new one with more specific context if this error occurs again with last version.

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