Tracy reports "Missing template file ‘send.latte’

jdan1131x
Member | 41
+
0
-

When I do this, everything works fine,

Public function handleSend(?string $n): void {

			$from = 'validemailaddr';
			$mail = $this->message->setFrom($from)
				->addTo($n)
				->setSubject('test')
				->setHtmlBody('test');

			$sender = new SendmailMailer();
			$sender->send($mail);
}

but when i do this i get error "missing template file send.latte'

Public function handleSend(?string $n): void {

			$from = 'validemailaddr';
			$latte = new Engine('send.latte');
			$params = ['orderid' => 123];
			$mail2 = $this->message->setFrom($from)
				->addTo($n)
				->setHtmlBody(
					$latte->renderToString('send.latte',$params)

				);
			$sender->send($mail2);   //this is where the fail happens

and send.latte is in the same folder as the default.latte where the
link to the signal is displayed.

send.latte is

<html>
<head>
	<meta charset="utf-8">
	<title>Order Confirmation</title>
</head>
<body>
	<p>Hello {$user->getIdentity()->name},</p>
	<p>Your new Latte email sender is working with ID: {$orderid}.</p>
</body>
</html>

as usual, i have spent hours researching. overcame some,
but i am really unsure…hope there is easy answer…
thanks,
James

jdan1131x
Member | 41
+
0
-

I fixed it. by adding a folder in the web root www calledd ‘latte’
and then putting send.latte into this folder and adding path info

			$mail2 = $this->message->setFrom($from)
				->addTo($n)
				->setHtmlBody(
					$latte->renderToString('latte/send.latte',$params)
				);
			$sender->send($mail2);

But it BEGS the question, why does the framework not look
in the same directory as the default latte? instead of
forcing me to add a path…

i hope you can update the documentation to make it more clear
Here
, thanks very much

Marek Bartoš
Nette Blogger | 1165
+
+2
-

Relative paths are relative to the called script, not current file. www/index.php in your case, probably. Simply always use absolute paths __DIR__ . '/path/to/send.latte'. You couldn't find it in documentation because it's php basics, nothing framework-specific.

Last edited by Mabar (2021-04-24 22:08)