Right on thanks. Found it too after doing a little digging in the cookbook.
Thanks again, Dave -----Original Message----- From: brian [mailto:bally.z...@gmail.com] Sent: September-22-09 10:44 PM To: cake-php@googlegroups.com Subject: Re: Element question That's because the element relies on $viewVars. $award is outside the element's scope because you created it in your view. At least, I believe that's the case. Do this instead: echo $this->element('users/block_awards', array('award' => $award)); That should pass your var to the element. On Tue, Sep 22, 2009 at 8:51 PM, Dave Maharaj :: WidePixels.com <d...@widepixels.com> wrote: > > I am trying to use an element inside a foreach loop. > I have the same code in 3 places and figured it would be easier to put > the duplicated code into an element and just render the 1 where needed. > > I put the element inside the foreach because the $award is is > different how it is obtained, its not always foreach ($user['Award'] > as $award) that's why I left it outside the element. > > example: > > foreach ($user['Award'] as $award):?> > > <?php echo $this->element('users/block_awards'); ?> > > <?php endforeach; ?> > > OR > > foreach ($campaign['User']['Award'] as $award):?> > > <?php echo $this->element('users/block_awards'); ?> > > <?php endforeach; ?> > > But the $award inside the element comes back Undefined variable: award > > Am I missing something here? Cant be done this way? > > > Dave > > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~---