yii2-email-templates

Extension for creating email templates and manage using your site dashboard

Github星跟踪图

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.

SymfonyInsight

Build Status
Scrutinizer Code Quality
Total Downloads
Latest Stable Version

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

  1. 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 code

    Subject

    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 {}.

  2. Now you can get this template in your code

    $template = Yii::$app->get('templateManager')->getTemplate('register-notification');
    

    This method returns a template model object.

  3. 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.

  4. 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.

License

License

This project is released under the terms of the BSD-3-Clause license.

Copyright (c) 2017-2018, Yii Maker

主要指标

概览
名称与所有者yiimaker/yii2-email-templates
主编程语言PHP
编程语言PHP (语言数: 1)
平台
许可证BSD 3-Clause "New" or "Revised" License
所有者活动
创建于2017-04-04 14:32:37
推送于2024-10-02 20:51:46
最后一次提交2024-10-02 23:50:03
发布数14
最新版本名称v4.1.2 (发布于 )
第一版名称1.0.0 (发布于 )
用户参与
星数91
关注者数15
派生数19
提交数166
已启用问题?
问题数29
打开的问题数2
拉请求数26
打开的拉请求数0
关闭的拉请求数34
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?