Knowledge Base

Javascript parse error “syntax error, unexpected T_STRING”

If Javascript in a template is causing a parse error that looks something like:

Parse error:  syntax error, unexpected T_STRING in path/to/system/core/core.functions.php(626) : eval()'d code on line 1

then the issue is likely due to a lack of whitespace in the Javascript code that is causing some parts of it to be parsed as ExpressionEngine conditionals.

Example:

function foo(){if(cond...

The lack of whitespace in this snippet would cause the template engine to parse the statement as an ExpressionEngine conditional. 

Corrected code:

function foo() { if (cond...

This statement addresses the issue by adding whitespace, but the readability can still be improved:

function foo()
{
    
if (cond...
        ...
}

Last Updated on Feb 27, 2007 at 09:45   ( Permalink )
Category: Templates, Other, Technical Issues, Troubleshooting