Currently I'm finding I have to keep duplicating partials for different modules.
I would like to have a case directory for all partials to be accessed.
Does anyone have a good way of doing this?
Thanks
$this->partial('directoryOfPartials/partial.phtml', $model);
I think you can also use $this->partial with three arguments. The second argument is a module name and the third argument becomes the model.
Taken From: http://framework.zend.com/manual/en/zend.view.helpers.html
Example #10 Rendering Partials in Other Modules Sometime a partial will exist in a different module. If you know the name of the module, you can pass it as the second argument to either partial() or partialLoop(), moving the $model argument to third position. For instance, if there's a pager partial you wish to use that's in the 'list' module, you could grab it as follows:
<?php echo $this->partial('pager.phtml', 'list', $pagerData) ?>
In this way, you can re-use partials created specifically for other modules. That said, it's likely a better practice to put re-usable partials in shared view script paths.
EDIT - Accessing view partials from within a Controller's Action scope
$this->view->getHelper('partial')->partial('comments.phtml');
Excellent thanks :)
However, how do I do this via the controller? I have fancybox and have set up the ajax layout:
$this->view->layout()->setLayout('ajax');
$errors = array('You have lost your rights to download this clip, you have downloaded it the maximum amount of times.');
$this->render($this->view->partial('partials/errors.phtml', 'default', array('errors' => $errors)), NULL, true);
The pop up window as required but with the following error:
Problem: Method "partial" does not exist and was not trapped in __call()
I kinda of assumed the $this->view->partial would be the same as using $this->partial inside the view template, but I guess not. Ideas?
SOLVED VIA:
Bootstrap initView, added:
$view->addScriptPath('../application/layouts/partials');
Moved my partials to that directory. Then in my controller I do:
$this->view->layout()->setLayout('ajax');
$this->view->form = $form;
$this->renderScript('login.phtml');
Thanks goes out to #zftalks SmartSsa
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