You could also use a partial. Partials handle the cloning/var-clearing for you.
Also, be careful with getViewScript(), because it adds a suffix based on the context. It's .phtml by default, but it could be .ajax.phtml if you're using the AjaxContext action helper. -- Hector Virgen Sent on my Droid X On Aug 11, 2010 7:30 AM, "Ryan Lange" <[email protected]> wrote: If anyone's interested, I've found a workable solution: <?php $mail_view = clone $this->view; $mail_view->clearVars(); $mail = new Zend_Mail( 'UTF-8' ); $mail->setBodyHtml( $mail_view->render( $this->getHelper( 'ViewRenderer' )->getViewScript( 'emails/client' ) ) ); ?> This code is placed within an action method. Cloning the controller's view object allows me to use the automatically generated paths for the view rather than build them up from scratch myself. So, the view script that gets rendered might be something like "/application/views/scripts[controller]/[action]/emails/client.[suffix]" or, if within a module, "/application/modules/[module]/views/scripts[controller]/[action]/emails/client.[suffix]". This only works because ViewRenderer::getViewScript() accepts directory separators in the action name. That seems odd to me, but I'm thankful for it at the moment. On Wed, Feb 24, 2010 at 9:46 PM, Ryan Lange <[email protected]> wrote: > Using the Zend_Application and the whole MVC shebang I have a controller > action that needs to assemble and send an HTML email. I want to use > Zend_View to render the body of the email and would like to keep the view > script in a subfolder of the controller's view script folder. > > I understand that the ViewRenderer action helper is responsible for setting > the script path based on module/controller when "auto-rendering", but I'm > not sure how to use that to my advantage for mid-action rendering, or if > it's even possible. > > I could set the script path manually, but I was hoping for an easier and > less error-prone (say, in the event of a refactoring) method. > > > Thanks in advance, > Ryan >
