Skip to content
This repository was archived by the owner on May 5, 2019. It is now read-only.

Commit 496f497

Browse files
committed
Add Handlebars::renderFile
1 parent 8d9f867 commit 496f497

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

Diff for: src/Handlebars.php

+19
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,25 @@ public function render($tmpl, $context = null, $options = array())
294294
}
295295
}
296296

297+
/**
298+
* Render a template from a file
299+
*
300+
* @param $filename
301+
* @param $context
302+
* @param $options
303+
* @return string
304+
* @throws \Handlebars\CompileException
305+
* @throws \Handlebars\RuntimeException
306+
*/
307+
public function renderFile($filename, $context = null, $options = array())
308+
{
309+
if( $this->mode === self::MODE_CVM ) {
310+
return $this->cvm->renderFile($filename, $context, $options);
311+
} else {
312+
return $this->render(file_get_contents($filename), $context, $options);
313+
}
314+
}
315+
297316
/**
298317
* Render a template in compiler mode
299318
*

Diff for: tests/HandlebarsTest.php

+6
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ public function testRenderSupportsStdClass()
7777
)
7878
)));
7979
}
80+
81+
public function testRenderFile()
82+
{
83+
$handlebars = new Handlebars(array('mode' => Handlebars::MODE_CVM));
84+
$this->assertEquals('bar', $handlebars->renderFile(__DIR__ . '/fixture1.hbs', array('foo' => 'bar')));
85+
}
8086

8187
public function testGH29RCEFix()
8288
{

Diff for: tests/fixture1.hbs

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{{foo}}

0 commit comments

Comments
 (0)