【问题标题】:Mustache Php: partials constructor not workingMustache Php:部分构造函数不起作用
【发布时间】:2018-11-22 11:36:51
【问题描述】:

我正在尝试加载一个寺庙,并且该模板中有一个部分(嵌套模板)。 partials 构造函数不应该渲染content 部分吗?逻辑做错了吗? 类似的问题here,但实现方式不同,没有答案。这个问题似乎已经死了,或者被指向了一些类似的问题,但我的问题在实现上也不同。

base.mustache:

<body>  
{{>content}}
</body>

Mustache 构造函数:

if(!isset($this->mustache)){
            $options = array(
              'loader'=> new Mustache_Loader_FilesystemLoader('path/to/templates/'),
              'partials_loader' => new Mustache_Loader_FilesystemLoader('path/to/partials'),
              'partials' => array(
                  'content'=> $this->module->tplFile
              )
            );
            $this->mustache = new Mustache_Engine($options);
        }

渲染模板:

public function display()
    {
      $this->mustache->render('base.mustache');
    }

【问题讨论】:

    标签: mustache.php


    【解决方案1】:

    首先,你甚至没有加载模板。

    只需像这样编辑您的渲染模板部分:

    public function display(){
      $this->mustache->loadTemplate('base')->render();
    }
    

    你可能会问,为什么只使用 'base' 而不是 'base.mustache'

    嗯,Mustache 默认加载一个.mustache 文件,所以如果你使用$this-&gt;mustache-&gt;loadTemplate('foo'),它会自动在你为文件加载器设置的路径下加载一个foo.mustache 文件。

    有关更多信息,您可以查看 mustache.php 官方 wiki 中的 Template Loading 部分。

    顺便说一句,我的英语很烂,所以希望你明白我在说什么。

    【讨论】:

      猜你喜欢
      • 2015-11-11
      • 1970-01-01
      • 1970-01-01
      • 2012-09-02
      • 2012-01-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多