dimanche 3 juin 2018

How can i use variable inside template literals?

Here is my code, and the problem is with variable unosAutor. I need to check if two strings are same with helper equal, but how to use variable unosAutor in template literals. When i put "some text" instead of unosAutor it works.

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>2 kolokvijum</title>
</head>
<body>
    Unesite ime autora: <input id="imeAutora" type="text" placeholder="Ime autora"><br><br>
    <button id="btnAutor" type="submit" onClick="proveraAutora()">Prikazi</button><br><br>
    <div id="sadrzaj"></div>

    <script src="js/handlebars-v4.0.11.js"></script>
    <script src="js/qwest.min.js"></script>
    <script src="js/jquery-3.2.1.min.js"></script>
    <script>
        function proveraAutora(){
            var unosAutor = document.querySelector("#imeAutora").value;
            var knjigeTemplate = 
            `
                
                
                    <h2> </h2>
                    <img src=""></img>
                    <h4>Broj strana: </h4>
                    <h4><b>Cena: </b></h4>
                
                
            `;

            var divSadrzaj = document.querySelector("#sadrzaj");

            qwest.get('data/json.json').then(function(xhr, response){
                var Render = Handlebars.compile(knjigeTemplate);
                divSadrzaj.innerHTML = Render({knjige : response});
            });

        };  
        Handlebars.registerHelper('equal', function(lvalue, rvalue, options) {
            if (arguments.length < 3)
                throw new Error("Handlebars Helper equal needs 2 parameters");
            if (lvalue != rvalue) {
            return options.inverse(this);
            } else {
                return options.fn(this);
            }
        });
    </script>
</body>
</html>




Aucun commentaire:

Enregistrer un commentaire