Created
January 6, 2022 05:51
-
-
Save mahammad/68f9338fb5687b13557746e35c084744 to your computer and use it in GitHub Desktop.
Email Template Content Replace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if (!function_exists('staticMailTemplateReplace')) { | |
function staticMailTemplateReplace($scope, object $data = NULL) | |
{ | |
$templates = Cache::get('templates', function () { | |
return (new Template())->on('mysql_license')->get(); | |
}); | |
$template_options = Cache::get('template_options', function () { | |
return (new TemplateOption())->on('mysql_license')->get(); | |
}); | |
$template = $templates->where('scope', $scope)->first(); | |
$email_content = @$template->email_content; | |
$email_title = @$template->email_title; | |
$template_options = $template_options->whereIn('key', get_string_betweens($email_content))->values(); | |
foreach ($template_options->whereIn('key', get_string_betweens($email_content))->values() as $option) { | |
$email_content = str_replace($option->key, $option->content ?: $data->{$option->type}, $email_content); | |
} | |
foreach ($template_options->whereIn('key', get_string_betweens($email_content))->values() as $option) { | |
$email_title = str_replace($option->key, $option->content ?: $data->{$option->type}, $email_title); | |
} | |
return (object)[ | |
'subject' => $email_title, | |
'text' => $email_content, | |
]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment