|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
shatyro Smarty n00b
Joined: 23 Aug 2017 Posts: 2
|
Posted: Wed Aug 23, 2017 1:38 pm Post subject: expected expression, got '<' - error JavaScript |
|
|
Hey there,
when I try to include JavaScript into my template, it behaves weirdly. Sometimes it works sometimes I get:
"SyntaxError: expected expression, got '<'".
As soon as I remove the JavaScript includes, it works again.
Anyone have an idea?
Code: | $this->view = new Smarty();
$this->view->setCompileDir(__DIR__ . '/../views/smarty-compile');
$this->view->setTemplateDir(__DIR__ . '/../views');
$this->view->display("login/login.tpl");
|
login.tpl
Code: | <!DOCTYPE HTML>
<html>
<head>
{literal}
<script src='app/libs/jquery-3.2.1.js'></script>
{/literal}
<meta charset="UTF-8">
</head>
<body>
<form id="login">
<input id="usr" type="text" value="username"><br>
<input id="pw" type="password" value="password"><br>
<input type="submit">
</form>
{literal}
<script src='app/js/login.js'></script>
{/literal}
</body>
</html> | [/code]
Thanks! |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Wed Aug 23, 2017 1:54 pm Post subject: Re: expected expression, got '<' - error JavaScript |
|
|
shatyro wrote: |
login.tpl
<!DOCTYPE HTML>
|
Must be "<!DOCTYPE html>".
XML doctype declaration is case-sensitive.
Quote: | <html>
<head>
{literal}
<script src='app/libs/jquery-3.2.1.js'></script>
{/literal}
|
{literal} here is useless.
Quote: |
<meta charset="UTF-8">
</head>
<body>
<form id="login">
<input id="usr" type="text" value="username"><br>
<input id="pw" type="password" value="password"><br>
<input type="submit">
</form>
{literal}
<script src='app/js/login.js'></script>
{/literal}
|
Move this include into the header and use either body onload, or form change events.
I see nothing in your template that could prompt the issue, which make me believe you are not reading your error messages correctly and not paying attention to your JS code. |
|
Back to top |
|
bsmither Smarty Elite
Joined: 20 Dec 2011 Posts: 322 Location: West Coast
|
Posted: Wed Aug 23, 2017 3:26 pm Post subject: |
|
|
If there is more to this code than what was posted, and if the error message is coming from the browser's javascript engine and is shown in the javascript error console, as opposed to PHP throwing the error and showing it in the document window, then there may a situation like this:
Code: | var x = <?php echo $data ?> |
This is caused by the PHP code not being executed.
So, let's have a look at login.js (we can assume jquery.js is fine). |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|