feat(template): added static method for template creation from file
This commit is contained in:
parent
47084b2835
commit
2919e70d05
3 changed files with 30 additions and 6 deletions
|
@ -1515,9 +1515,9 @@ App::post('/v1/account/recovery')
|
|||
$url['query'] = Template::mergeQuery(((isset($url['query'])) ? $url['query'] : ''), ['userId' => $profile->getId(), 'secret' => $secret, 'expire' => $expire]);
|
||||
$url = Template::unParseURL($url);
|
||||
|
||||
$body = new Template(__DIR__.'/../../config/locale/templates/email-base.tpl');
|
||||
$body = Template::fromFile(__DIR__.'/../../config/locale/templates/email-base.tpl');
|
||||
$content = Template::fromHtmlString($locale->getText('account.emails.recovery.body'));
|
||||
$cta = new Template(__DIR__.'/../../config/locale/templates/email-cta.tpl');
|
||||
$cta = Template::fromFile(__DIR__.'/../../config/locale/templates/email-cta.tpl');
|
||||
|
||||
$body
|
||||
->setParam('{{content}}', $content->render(false))
|
||||
|
@ -1719,9 +1719,9 @@ App::post('/v1/account/verification')
|
|||
$url['query'] = Template::mergeQuery(((isset($url['query'])) ? $url['query'] : ''), ['userId' => $user->getId(), 'secret' => $verificationSecret, 'expire' => $expire]);
|
||||
$url = Template::unParseURL($url);
|
||||
|
||||
$body = new Template(__DIR__.'/../../config/locale/templates/email-base.tpl');
|
||||
$body = Template::fromFile(__DIR__.'/../../config/locale/templates/email-base.tpl');
|
||||
$content = Template::fromHtmlString($locale->getText('account.emails.verification.body'));
|
||||
$cta = new Template(__DIR__.'/../../config/locale/templates/email-cta.tpl');
|
||||
$cta = Template::fromFile(__DIR__.'/../../config/locale/templates/email-cta.tpl');
|
||||
|
||||
$body
|
||||
->setParam('{{content}}', $content->render(false))
|
||||
|
|
|
@ -419,9 +419,9 @@ App::post('/v1/teams/:teamId/memberships')
|
|||
$url['query'] = Template::mergeQuery(((isset($url['query'])) ? $url['query'] : ''), ['membershipId' => $membership->getId(), 'teamId' => $team->getId(), 'userId' => $invitee->getId(), 'secret' => $secret, 'teamId' => $teamId]);
|
||||
$url = Template::unParseURL($url);
|
||||
|
||||
$body = new Template(__DIR__.'/../../config/locale/templates/email-base.tpl');
|
||||
$body = Template::fromFile(__DIR__.'/../../config/locale/templates/email-base.tpl');
|
||||
$content = Template::fromHtmlString($locale->getText('account.emails.invitation.body'));
|
||||
$cta = new Template(__DIR__.'/../../config/locale/templates/email-cta.tpl');
|
||||
$cta = Template::fromFile(__DIR__.'/../../config/locale/templates/email-cta.tpl');
|
||||
$title = \sprintf($locale->getText('account.emails.invitation.title'), $team->getAttribute('name', '[TEAM-NAME]'), $project->getAttribute('name', ['[APP-NAME]']));
|
||||
|
||||
$body
|
||||
|
|
|
@ -5,9 +5,32 @@ namespace Appwrite\Template;
|
|||
use Exception;
|
||||
use Utopia\View;
|
||||
|
||||
use function PHPUnit\Framework\isReadable;
|
||||
|
||||
class Template extends View
|
||||
{
|
||||
|
||||
/**
|
||||
* fromFile
|
||||
*
|
||||
* Creates a new Template() from the file at $path
|
||||
*
|
||||
* @param string $path
|
||||
*
|
||||
* @return self
|
||||
*
|
||||
*/
|
||||
public static function fromFile(string $path): self
|
||||
{
|
||||
if (\is_readable($path)) {
|
||||
throw new Exception("$path view template is not readable.");
|
||||
}
|
||||
|
||||
$template = new Template();
|
||||
return $template->setPath($path);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
|
@ -28,6 +51,7 @@ class Template extends View
|
|||
if (empty($html)) {
|
||||
throw new Exception('Empty HTML string');
|
||||
}
|
||||
|
||||
$template = new Template();
|
||||
return $template->setHtml($html);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue