Skip to content
Grav 2.0 is officially stable. Read the announcement →
Archive

Using HTML Templates with grav['Email']

Started by Muut Archive 10 years ago · 2 replies · 890 views
10 years ago

Hey guys. I'm trying to use a template for sending an email. I realize there is no documentation for this so I'm following what they do in the admin plugin.

My plugin estructura is this:
--- md
getform
templates
base.html.twig
getform.php
getform.yaml

PHP
And in geform.php I have the following: 
--- php
$body = $this->grav['twig']->processTemplate('base.html.twig', ['header'=>$header,'content' => $content]);
$message = $this->grav['Email']->message($subject, $body, 'text/html')
   ->setFrom($from)
   ->setTo($to);

$sent = $this->grav['Email']->send($message);

Now. This is giving me a resource not defined error. Then found out something else they do in Admin, they find and then load the resources. With something like this:
---php
$template_paths = $this->grav['locator']->findResources('/templates');
$loader_chain = $this->grav['twig']->twig->getLoader()->addLoader(new \Twig_Loader_Filesystem($template_paths));

TXT

But that still is NOT working for me. It gives me an **invalid resource** error.

Don't know what to do. Any ideas?
Thanks.
10 years ago

My bad. In processTemplate method I use '/templates/base.html.twig', './templates/base.html.twig' and even just 'base.html.twig' but still the same Template not defined Error.

10 years ago

base.html.twig is generally a partial. It's under the partials folder, so use partials/base.html.twig

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1357 9 years ago
Archive · by Muut Archive, 9 years ago
2 936 9 years ago
Archive · by Muut Archive, 9 years ago
2 4066 9 years ago
Archive · by Muut Archive, 9 years ago
1 2954 9 years ago
Archive · by Muut Archive, 9 years ago
3 1120 9 years ago