Search code examples
javascriptunderscore.js-templating

underscore template is not is not showing for popover function?


// html.erb(template)
<script id="temp">
 <p><%= name %></p><!--the name is to fetch value passed in template -->
</script>

//script.js
//declaring variables for template
var _slicer=$('#temp').html();
//popover function
$(linkingmoduleobj).popover({
        container : 'body',
        html : 'true',
        content : "some content,
        title : "some title",
        template : '_.template(_slicer,{name: "praveen"})'
    })

inside _.template when directly use the html code instead of passing variable it is working when i pass reference variable for template it is not working


Solution

  • <script id="temp" type = "text/template">
         <p><%= name %></p>
    </script>
    <div id="aa"></div>
    <script>
    var _slicer=$('#temp').html();
    //popover function
    $('#aa').html(_.template(_slicer)({name: "praveen"}));
    </script>
    

    just change it the way you want to but the code to be changed is

    _.template(_slicer)({name: "praveen"}) 
    

    and

     <script id="temp" type = "text/template">