Jump to content

Weird problem with $page->render()


thomas
 Share

Recommended Posts

Hi,

I'm fighting with a weird problem here. I'm trying to build a mass mailer app with personalized HTML emails. The workflow is as follows:

 

foreach($recipients as $to) {
	$this->wire->set('recipient_email', $to->email);
	$htmlBody = $nl->render();
	$key = $sanitizer->pageName($to->email.$nl->id.time());
	$cache->get($key);
	$cache->save($htmlBody);
	$sendArray[] = ['to'=>$to->email,'cache_key'=>$key];
}

So the personalized HTML is written into a MarkupCache and the key written to an array. In the next step I send the cached HTML to each of the recipients.

The Newsletter template itself has an "articles" Pagefield which references articles included in the newsletter. I use

$first = $page->articles->shift();

for the first article and then iterate over the rest. When simply displaying the Newsletter Page via it's url everything works perfect. Now when using $page->render(); the $first PageObject returns errors ("Trying to get property of non-object")

I tried explicitly setting output formatting (always on), but that doesn't help. If I remove the whole $first set, everything works fine.

My only guess is that this has to do with $page->render(). Is there anything I need to know?

Thanks,

thomas

 

 

[Turns out this was a problem with the foreach loop using render(). The error always occured after the 6th iteration. I now switched to a single render() and replace the dynamic parts using preg_replace_callback()]

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...