Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/440.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 运行木偶的Web包应用程序中的外部模板_Javascript_Templates_Dependencies_Marionette_Webpack - Fatal编程技术网

Javascript 运行木偶的Web包应用程序中的外部模板

Javascript 运行木偶的Web包应用程序中的外部模板,javascript,templates,dependencies,marionette,webpack,Javascript,Templates,Dependencies,Marionette,Webpack,我正在用Webpack设置一个应用程序,并用主干木偶运行前端。我已经设法让应用程序脚本运行[在应用程序模块中的控制器内生成布局视图,就像在AMD/Require中一样],但我无法弄清楚的是模板化 过去,我使用下划线模板,但webpack更喜欢玉和把手。我切换到Jade,但我的LayoutView仍返回错误: Uncaught UndefinedTemplateError:无法呈现模板,因为它为null或未定义 当我从控制台注销呈现的Jade模板时,我得到: 以下是我的LayoutView代码供查

我正在用Webpack设置一个应用程序,并用主干木偶运行前端。我已经设法让应用程序脚本运行[在应用程序模块中的控制器内生成布局视图,就像在AMD/Require中一样],但我无法弄清楚的是模板化

过去,我使用下划线模板,但webpack更喜欢玉和把手。我切换到Jade,但我的LayoutView仍返回错误:

Uncaught UndefinedTemplateError:无法呈现模板,因为它为null或未定义

当我从控制台注销呈现的Jade模板时,我得到:

以下是我的LayoutView代码供查看:

Marionette = require 'marionette'
AppLayoutTemplate = (require 'templates/appLayoutTemplate.jade')()
console.log AppLayoutTemplate

class AppLayoutView extends Marionette.LayoutView
  initialize: ->
    template: AppLayoutTemplate
    regions:
      glossaryContainer: '.glossary-container'

为了使用
把手
作为带有
木偶的模板引擎
,您需要重写
木偶
中的一些方法

我建议您在木偶网中加载模板,并使用某种缓存:

第一次重写:

重写

在此之后,加载您的视图,如:

Marionette = require 'marionette'
    class AppLayoutView extends Marionette.LayoutView
      initialize: ->
        template: 'path_to_your_template/without_extension'
        regions:
          glossaryContainer: '.glossary-container'

这将适用于车把。我不熟悉玉,但我相信它应该是一样的

这是由于语法错误造成的。我错误地将
模板
散列嵌套在
initialize->
方法中。回答我自己的问题,希望它能帮助其他人。

木偶中的任何视图都希望编译后的模板能够呈现数据。默认情况下-下划线编译为函数,在使用JSON模型呈现时将调用此函数。如果您需要实现其他模板引擎支持,您必须重新编写marionete.renderevahan,谢谢您的回答。这在将来确实会有帮助。不幸的是,我的修复是一个愚蠢的语法错误。将“模板”散列嵌套在initialize方法中,而该方法本应位于根。对于遇到同样问题的人,我将在下面回答我自己的问题。
Marionette.TemplateCache.prototype.compileTemplate = function (yourTemplate) {
    if ($.isFunction(yourTemplate)) {
        return yourTemplate;
    } else {
        return Handlebars.compile(yourTemplate);
    }
};
Marionette = require 'marionette'
    class AppLayoutView extends Marionette.LayoutView
      initialize: ->
        template: 'path_to_your_template/without_extension'
        regions:
          glossaryContainer: '.glossary-container'