Skip to content

Commit

Permalink
Add ability to add custom welcome template
Browse files Browse the repository at this point in the history
This adds the ability to add a custom welcome template.
It works by simply adding a custom folder in the templates
directory and putting a email/html/welcome.html.twig and
email/text/welcome.txt.twig there (as you can read in the
README).
  • Loading branch information
rrooij committed Apr 14, 2024
1 parent f2292c3 commit 03311c8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ Go to `http://localhost:8080/` and you should be greeted by the MijnRood login p
You can log in with `[email protected]` as email, and `admin` as password.
Look at `src/DataFixtures/` to see an overview of all test data, including other accounts.

## Extra configuration

### Custom welcome mail

To add a custom welcome email, put the two templates (html and plain text) in:

`templates/custom/email/welcome.html.twig` and `templates/custom/email/welcome.html.txt`

## Contributing

You can generate new migrations with:
Expand Down
10 changes: 8 additions & 2 deletions src/Controller/Admin/MembershipApplicationCrud.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,21 @@ public function acceptApplication(AdminContext $context)
$em->remove($application);
$em->flush();

$templatePrefix = '';

if (is_dir($this->getParameter('kernel.project_dir') . '/templates/custom')) {
$templatePrefix = 'custom/';
}

$message = (new Email())
->subject("Welkom bij $organizationName!")
->to(new Address($member->getEmail(), $member->getFullName()))
->from(new Address($noreply,$organizationName))
->html(
$this->renderView('email/html/welcome.html.twig', ['member' => $member])
$this->renderView($templatePrefix . 'email/html/welcome.html.twig', ['member' => $member])
)
->text(
$this->renderView('email/text/welcome.txt.twig', ['member' => $member])
$this->renderView($templatePrefix . 'email/text/welcome.txt.twig', ['member' => $member])
);
$mailer->send($message);

Expand Down

0 comments on commit 03311c8

Please sign in to comment.