Solved

JavaScript syntax question (Urgent please)

Posted on 2015-02-17
1
95 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Because your company can’t afford for you to make SEO mistakes, you’ll want to ensure you’re taking the right steps each and every time you post a new piece of content. This list of optimization do’s and don’ts can help you become an SEO wizard.
Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

831 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