0

I'd like to generate html code from volt template to variable. How to do this?

$this->view->pick('foo/bar');
$this->view->setVar('foo', $bar);
$html = $this->view->???
Robin71
  • 383
  • 5
  • 26

1 Answers1

1

There are many different ways to load the content of your views into a variable.

One way is to return the output of your view as a string by calling render on your $view.
This will only load the specific view and not the template.

$this->view->setVar('foo', $bar);
$html = $this->view->getRender('controller', 'action');

An other option to load your view (with a template):

$this->view->start();
$this->view->setVar('foo', 'test');
$this->view->setTemplateAfter('default'); // template name
$this->view->render('controller', 'action');
$this->view->finish();

$html = $this->view->getContent();

In the documentation you can also find other ways to achieve this.

Timothy
  • 2,004
  • 3
  • 23
  • 29