2
<div class="tab-pane active" id="connectedDevices">
                     <script>

                      if (req.user.pebble.watch_token == String) {
                        <i class="fa fa-check"> Pebble </i>
                      } else{
                        <i class="fa fa-warning">No Pebble connected</i>
                      };

                     </script>


                  </div>

Using local strategy and Pebble kit to verify if a user has a pebble connected. All the AUTH is working, just wondering why nothing is showing up now.

2 Answers2

2

You are getting an error because < isn't allowed where you are putting it. You have a < because you have placed some HTML in the middle of your JavaScript.

You say, in the comments, that you are using EJS, but if you were using the syntax shown on the homepage then your template would look like this:

<% if (req.user.pebble.watch_token == String) { %>
    <i class="fa fa-check"> Pebble </i>
<% } else { %>
    <i class="fa fa-warning">No Pebble connected</i>
<% } %>

and would be in a .ejs template file loaded with:

var html = new EJS({url: 'example.ejs'}).render(data);

You would then have the HTML in a variable that you could use with innerHTML on an element.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
-2

You need to be inside of a script tag (i.e. ) in order to do what you're doing. It is called In-Line Javascript and is very useful.

user1789573
  • 515
  • 2
  • 8
  • 23
  • If it wasn't in a script element, it wouldn't be causing the browser to display a script error. – Quentin Mar 02 '15 at 19:02
  • I am using the tags, I figured people would realize – Eric William Dolan Mar 02 '15 at 19:02
  • No, it actually wouldn't. It would continue to throw syntactical errors. – user1789573 Mar 02 '15 at 19:03
  • 1
    @user1789573 — No, it would treat the JS as text and the HTML as HTML (instead of treating the JS as JS and the HTML as an error) – Quentin Mar 02 '15 at 19:03
  • But, you forget it is the difference between being INSIDE a tag, and OUTSIDE a tag. If it's OUTSIDE a tag then it will just be displayed as text. If it's INSIDE a tag then it throws an error. But, an easy way to end the argument is to have the OP just post the ENTIRE code snippet. – user1789573 Mar 02 '15 at 19:05
  • @user1789573 — Nobody forgot that. That is, in fact, what I said in my last comment. We know that the OP put it in a script element because (a) we know it throws an error and (b) they said they did. – Quentin Mar 02 '15 at 19:08
  • It actually does't say – user1789573 Mar 02 '15 at 19:16