Jump to content

$files->render() don't set $vars?


Recommended Posts

Hi there,

I'm working on an email message template and would like to render a custom one to be sent.

I tried to use $files->render() this way

// rendering file e.g. a template file or a hook statement in ready.php
$body = $files->render('emails/myfile', array(
  'myVar1' => $var1,
  'myVar2' => $var2,

but $vars seems to be not accessible from within the rendered file. That is, $vars seems to be not set:

// rendered file emails/myfile.php
$myVar1 = $vars['myVar1']; // is not set
$myVar2 = $vars['myVar2']; // is not set
... // is not set

How can I get the $vars so to properly render the custom message template for sending the email?



  • By using $files->include() the $vars is accessible but I cannot use this method because I should retrieve the output $body as a return value for sending the email later. So, I'm still looking to render the custom message using $files->render().
  • This thread is someway related to this one.
Link to comment
Share on other sites

@Robin S OK for $myVar1 and $myVar2 (string variables) 🙂 ... but it seems do not work when I pass a PW Page 😕

// rendering file
$myPage = $pages->get(12345);
$body = $files->render('emails/myfile', array(
  'myPageVar' => $myPage
// rendered file emails/myfile.php
isset($myPageVar); // returns false

Strange 🤔

Link to comment
Share on other sites

  • 5 months later...

Had the same issue as @LAPS, ie $vars not accessible in the rendered template. Fixed by including an empty array for $options, ie:


$vars = [
    'items' => $items,
    'homepage' => pages(1),
    'category' => $category
echo $files->render('inc/item-detail',$vars,[]);


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

  • Create New...