Webiny\Component\TemplateEngine\Bridge\Smarty\Smarty::fetch PHP Method

fetch() public method

Fetch the template from the given location, parse it and return the output.
public fetch ( string $template, array $parameters = [] ) : string
$template string Path to the template.
$parameters array A list of parameters to pass to the template.
return string Parsed template.
    public function fetch($template, $parameters = [])
    {
        try {
            if (count($parameters) > 0) {
                $this->smarty->assign($parameters);
            }
            return $this->smarty->fetch($template);
        } catch (\Exception $e) {
            throw new SmartyException($e->getMessage());
        }
    }

Usage Example

Example #1
0
 /**
  * @dataProvider dataProvider
  */
 public function testRegisterExtensions(Smarty $smarty)
 {
     DemoComponent::setConfig(__DIR__ . '/Mocks/DemoComponentConfig.yaml');
     $smarty->registerExtensions();
     $smarty->assign('name', 'WORLD');
     $result = $smarty->fetch('DemoComponent.tpl');
     $this->assertSame('Hello world', $result);
 }