Jade\Jade::render PHP Method

render() public method

Compile HTML code from a Pug input or a Pug file.
public render ( $input, $filename = null, array $vars = [] ) : string
$vars array
return string
    public function render($input, $filename = null, array $vars = array())
    {
        if (is_array($filename) || is_object($filename)) {
            $vars = $filename;
            $filename = null;
        }
        $file = $this->options['cache'] ? $this->cache($input) : $this->stream($this->compile($input, $filename));
        extract(array_merge($this->sharedVariables, $vars));
        ob_start();
        try {
            include $file;
        } catch (\Exception $e) {
            ob_end_clean();
            throw $e;
        }
        return ob_get_clean();
    }

Usage Example

Ejemplo n.º 1
0
 public function testJsExpression()
 {
     $jade = new Jade(array('singleQuote' => false, 'expressionLanguage' => 'js'));
     $actual = trim($jade->render("- a = 2\n- b = 4\n- c = b * a\np=a * b\np=c"));
     $this->assertSame('<p>8</p><p>8</p>', $actual);
     $actual = trim($jade->render("- a = 2\n- b = 4\np=a + b"));
     $this->assertSame('<p>6</p>', $actual);
     $actual = trim($jade->render("- a = '2'\n- b = 4\np=a + b"));
     $this->assertSame('<p>24</p>', $actual);
     $compiler = new ExpressionCompilerTester(array('expressionLanguage' => 'js'));
     $actual = trim($compiler->callPhpizeExpression('addDollarIfNeeded', 'array(1)'));
     $this->assertSame('array(1)', $actual);
     $actual = trim($compiler->callPhpizeExpression('addDollarIfNeeded', 'a'));
     $this->assertSame('$a', $actual);
 }
All Usage Examples Of Jade\Jade::render