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
<[email protected]> 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 [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to