From 349f604ff70968a8f9b38f4c28f964a224d5ea6b Mon Sep 17 00:00:00 2001 From: Xorg Date: Thu, 31 Aug 2023 13:36:22 +0200 Subject: [PATCH] Add possibility to custom path twig template to render --- README.md | 15 +++++++++++++++ src/notify/EmailCustomer.php | 12 ++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index dccff49..6075e41 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,21 @@ It set automatique but you can custom emails: Partial\emails\ save_notify: true # by default true mean all notification send will be save in Db messenger ``` + +it's away possible to custom path twig template to render ! + +``` + as you can see in code if you setTemplate() to what eve "xxx/xxxx/xxx.tmh.twig it will set. + + // try to fund way to be able to have custom path to template + // $option->getTemplate() == "default" ; null ; "xxxx/xxxxx/default.html.twig" + $value = $option->getTemplate(); + $Template = match (true) { + str_contains($value, '/') => $value, + default => $this->neoxTemplate['emails'] . "/" . ($option->getTemplate() ? : 'default'). '.html.twig', + }; +``` + ## How to use ? ```php myController.php diff --git a/src/notify/EmailCustomer.php b/src/notify/EmailCustomer.php index ccf6ad3..e250ca3 100644 --- a/src/notify/EmailCustomer.php +++ b/src/notify/EmailCustomer.php @@ -37,9 +37,17 @@ public function asEmailMessage(EmailRecipientInterface $recipient, string $trans * markAsPublic() take all annotation symfony. * !!! neox_[xxxx] SETTING FOR TWIG PREFIX !!! >> $option->setContext */ - + + // try to fund way to be able to have custom path to template + // $option->getTemplate() == "default" ; null ; "xxxx/xxxxx/default.html.twig" + $value = $option->getTemplate(); + $Template = match (true) { + str_contains($value, '/') => $value, + default => $this->neoxTemplate['emails'] . "/" . ($option->getTemplate() ? : 'default'). '.html.twig', + }; + $email = $message->getMessage()->markAsPublic(); - $email->htmlTemplate( $this->neoxTemplate['emails'] . "/" . ($option->getTemplate() ? : 'default'). '.html.twig' ); + $email->htmlTemplate( $Template ); $option->setContext("subject",$option->getSubject()); $option->setContext("content",$option->getContent());