partial() and render() parameters? (v1.7.2)

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

partial() and render() parameters? (v1.7.2)

nphilliy
I am currently forced to use zend framework 1.7.2

I have a problem with the partial function

$this->partial('template.html', array('arg1' => 'value1'));

This kind of does what i want but the variables that are available to the parent template are not in the partial template

I know that $this->render('template.html'); allows the variables to be exposed to the template but it accepts no parameters

what about if i want the variables to be exposed to my partial template AND need parameters to be passed in? Did they actually not put something like this in?

yeap i know the partial() method is meant to give a clean variable scope and blah blah blah, so if thats the case, how do I do what im asking?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: (v1.7.2)

weierophinney
Administrator
-- nphilliy <[hidden email]> wrote
(on Thursday, 10 February 2011, 06:14 AM -0800):

>
> I am currently forced to use zend framework 1.7.2
>
> I have a problem with the partial function
>
> $this->partial('template.html', array('arg1' => 'value1'));
>
> This kind of does what i want as the variables that are available to the
> parent template are not in the partial template
>
> I know that $this->render('template.html'); allows the variables to be
> exposed to the template
>
> but what about if i want the variables to be exposed to my partial template
> AND need parameters to be passed in? Did they actually not put something
> like this in?
>
> yeap i know the partial() method is meant to give a clean variable scope and
> blah blah blah, so if thats the case, how do I do what im asking?

Two ways:

 * Use render(), and make sure the variables are already in the view
   script scope, or assigned to the view. In terms of having them in the
   view script scope:

   <?php
   $arg1 = 'value1';
   echo $this->render('template1.phtml'); // template can now refer to $arg1

 * Pass in all view variables + locally scoped variables:

   <?php
   $vars = $this->getVars();
   $vars['arg1'] = 'value1';
   echo $this->partial('template1', $vars);

--
Matthew Weier O'Phinney
Project Lead            | [hidden email]
Zend Framework          | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: (v1.7.2)

David Muir
weierophinney wrote
-- nphilliy <nathaniel.phillips@photobox.com> wrote
(on Thursday, 10 February 2011, 06:14 AM -0800):
>
> I am currently forced to use zend framework 1.7.2
>
> I have a problem with the partial function
>
> $this->partial('template.html', array('arg1' => 'value1'));

 * Use render(), and make sure the variables are already in the view
   script scope, or assigned to the view. In terms of having them in the
   view script scope:

   <?php
   $arg1 = 'value1';
   echo $this->render('template1.phtml'); // template can now refer to $arg1
Don't you mean:

<?php
$this->arg1 = 'value1';
$this->render('template1.phtml');
?>

Render is a bit faster than partial, so if the scope bleed isn't a problem, I'd use render().

Cheers,
David
Loading...