首页 > 解决方案 > Handlebars.compile 在页面中不起作用。但是,从控制台工作

问题描述

// 我在 html 页面中有以下代码。我正在尝试这个来学习 Handlebars.compile 功能。

<script src="https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.7.7/handlebars.min.js">
</script>
    
<script>
    // compile the template
  let template = Handlebars.compile("Hello {{message}}");
  // execute the compiled template and print the output to the console
  console.log(template({ message: "My friend" }));
</script>

//this outputs in console as - Hello
//But when I test this from console for the same page, like for example

let template2 = Handlebars.compile("Hello {{message}}");
console.log(template2({ message: "My friend" }));
//It outputs - Hello My friend

//I am wondering why same is not working from the page.

标签: handlebars.jsexpress-handlebarshandlebarshelperhandlebars.javahandlebars.net

解决方案


推荐阅读