doufei7464 2014-07-02 15:18 采纳率: 0%
浏览 42
已采纳

如何在php胡子引擎中获取模板源代码

I am trying to get a raw template that is already loaded by Mustache_Engine. On creation of the mustache object Filesystem_Loader instance is set up and pointing to the default directory.

$mustache = new Mustache_Engine( array(
    'loader' => new Mustache_Loader_FilesystemLoader( 'path-to-templates' )
) );

And later, for rendering the templates I use.

echo $mustache->render( 'template-name', $data ); 

The same template is used by mustache.js on server side, so i want to also print that template as inline script.

I could load the template from the filesystem manually with file_get_contents, but since that template is already loaded maybe there's a way to retrieve that from Mustache_Engine. Also, to use the file_get_contents i must use full path of the template and that just contradicts with the purpose of Mustache Template Loader.

  • 写回答

1条回答 默认 最新

  • duanfei1975 2014-07-02 16:06
    关注

    After digging through the Mustache_Engine source, found the answer. getLoader() will get the current Mustache Template Loader instance, and load() function will load the template ( if is not already loaded ) and return it as string.

    echo $mustache->getLoader()->load( 'template-name' );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题