Solved

JavaScript syntax question (Urgent please)

Posted on 2015-02-17
1
99 Views
Last Modified: 2015-03-13
I am using the following JavaScript code in a .html file for my Jetty web application:

<script id="user-template" type="text/x-handlebars-template">
    <img src="assets/images/admin/redminus.png" class="user-delete-img">
    <div class="user_name admin-users-span-1">{{username}}</div>
    <div class="user_email admin-users-span-2">{{username}}</div>
</script>

The above script works. It obtains the "username" variable as expected. I am creating another .html file where I am using the same "username" variable but I am experiencing problem with syntax and it is not working. The following are the .html file code. I have written three versions of it. Could you please let me know which one has the correct syntax? The first one did not work. If none has the correct syntax, could you please help me correct it?

1.
<script id="footer-template" type="text/x-handlebars-template">
        <img src="http://mypage.com/t.png?t=map&p={{username}}"/>
</script>

2.
<script id="footer-template" type="text/x-handlebars-template">
        <img src="http://mypage.com/t.png?t=map&p="/>{{username}}
</script>

3.
<script id="footer-template" type="text/x-handlebars-template">
        <img src="http://mypage.com/t.png?t=map&p="{{username}}/>
</script>
0
Comment
Question by:toooki
1 Comment
 
LVL 17

Accepted Solution

by:
Lucas Bishop earned 500 total points
ID: 40615939
What did not work with the first one? How did it render in your page source? Does t.png exist in the root directory?

I see version 1 as being correct. Here is an example of how each would render if username was johndough:

Version 1 would include johndough as a parameter on the image path with proper html syntax:
        <img src="http://mypage.com/t.png?t=map&p=johndough" />

Open in new window


Version 2 would render the image with an empty parameter for "p=" and the username "johndough" rendered in plain text next to the image.
<img src="http://mypage.com/t.png?t=map&p=" />johndough

Open in new window


Version 3 the image path would end with an empty "p=" and the username would likely cause the image to appear broken since it is not defined as being part of valid html code.
<img src="http://mypage.com/t.png?t=map&p="johndough />

Open in new window


If you create an image tag manually on the page, using a real username in the parameter string, does it render properly? For example:

        <img src="http://mypage.com/t.png?t=map&p=replacewithrealusername" />

Open in new window

0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Learn by example how to specify CSS selectors for Selenium WebDriver test automation software.
Color can increase conversions, create feelings of warmth or even incite people to get behind a cause. If you want your website to really impact site visitors, then it is vital to consider the impact color has on them.
The viewer will learn how to count occurrences of each item in an array.
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question