Reputation: 7338
I'd like to have some layouts for messages in my MessageComponent
.
Its send
method should get an array of variables which used in view (layout) and render message with them, then send it..
The question is:
How to render a view (layout) with an array of variables in a component? and get rendered content instead of print it (in a component, too)
Thanks.
Upvotes: 3
Views: 4991
Reputation: 8045
(Edit: Misread your question)
If you want to get the HTML of a rendered view, simply do something like:
$view = new View($this, false);
$view->set(compact('foo', 'bar')); // set variables
$view->viewPath = 'elements'; // render an element
$html = $view->render('message'); // get the rendered markup
This should work in a controller as well as a component.
Upvotes: 7