XF 2.2 foreach not working in email template

Dannymh

Active member
I have an email template and I am passing in an array that is sliced from a finder array.

When I then try to loop through that in an email template it isn't giving me the values.

HTML:
<xf:if is="$totalBidders > 0">
    <h2>High Bidders</h2>
    <xf:foreach loop="$bidders" value="$bidr">
        <a href={{ link('members', $bidr) . '#about' }}>{$bidr.User.username}</a> - {$bidr.User.email}
    </xf:foreach>
</xf:if>

My array has values that are returned from the finder
PHP:
$app = \XF::app();
        $user = $app->em()->find('XF:User', $lot->user_id);
        $bidders = \XF::finder('ledger:Bids')
        ->where('thread_id', '=', $lot->thread_id)
        ->with('User')
        ->with('Thread')
        ->order('bid_time', 'ASC'
->fetch();

If I loop through these on the cron I can list out the values with something like

PHP:
foreach($bidders as $bdr)
{
    echo $bdr->User->username;
}

but if I pass it in to my email template as a variable

PHP:
 $mail->setToUser($user)
                ->setTo($user->email, $lot->username)
                ->setTemplate('pass_on', [
                    'bidders' => $bidders
                ]);

It just returns the dash in the text and not the array

Any thoughts on what might be happening?
 
Last edited:
Are you also passing $totalBidders to the template?

Otherwise the foreach loop in the template won't be executed due to the if condition resulting in false
 
Hi,

No I am only using that to determine if there were bidders, and if so then loop through them. If there weren't no point trying to list them.

I am going to go bang my head against the wall and work on something else for a while and come back to it. I am sure its just something simple. I will just put some error logging in
 
Top Bottom