yiimaker / yii2-email-templates
Extension for creating of email templates and manage using your site dashboard
Installs: 15 368
Dependents: 1
Suggesters: 0
Security: 0
Stars: 93
Watchers: 16
Forks: 20
Open Issues: 2
Type:yii2-extension
Requires
- php: >=5.6.0
- motion/yii2-language-provider: ~2.1
- yiimaker/yii2-translatable: ~1.0.1
- yiisoft/yii2: ^2.0.13
Requires (Dev)
- codeception/codeception: ~3.0
- friendsofphp/php-cs-fixer: ^2.15
- yiisoft/yii2-gii: ~2.2.0
Suggests
- vova07/yii2-imperavi-widget: If you want use Imperavi editor you should install this package
- yiisoft/yii2-bootstrap: If you want use default view files in backend you should install this package
README
Email templates module
Extension for creating email templates and managing by using your site dashboard. You can create email templates with CRUD module in your backend or Gii generator.
Documentation is at docs/guide/README.md.
Installation
The preferred way to install this extension is through composer.
Either run
$ composer require yiimaker/yii2-email-templates
or add
"yiimaker/yii2-email-templates": "~4.1"
to the require
section of your composer.json
.
Usage
-
Create template with placeholders using your site dashboard or Gii generator
Key
register-notification
- this is unique key of this template for using in your codeSubject
Notification from {site-name}
In this example email subject has one placeholder
{site-name}
Body
Hello, {username}! Welcome to {site-name} :)
Email body has two placeholders:
{username}
and{site-name}
.All keys should be wrapped by
{}
. -
Now you can get this template in your code
$template = Yii::$app->get('templateManager')->getTemplate('register-notification');
This method returns a template model object.
-
Then you should parse this template
$template->parseSubject([ 'site-name' => Yii::$app->name, ]); $template->parseBody([ 'username' => Yii::$app->getIdentity()->username, 'site-name' => Yii::$app->name, ]);
or use another method
$template->parse([ 'subject' => [ 'site-name' => Yii::$app->name, ], 'body' => [ 'username' => Yii::$app->getIdentity()->username, 'site-name' => Yii::$app->name, ], ]);
this methods replace placeholders in template with real data.
-
Now you can use data of this template in your logic
Yii::$app->get('mailer')->compose() ->setSubject($template->subject) ->setHtmlBody($template->body) // ...
Tests
You can run tests with composer command
$ composer test
or using following command
$ codecept build && codecept run
Contributing
For information about contributing please read CONTRIBUTING.md.
Sponsoring
License
This project is released under the terms of the BSD-3-Clause license.
Copyright (c) 2017-2022, Yii Maker