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.
(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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With