Giter Club home page Giter Club logo

twiggedswiftmessageserviceprovider's Introduction

TwiggedSwiftMessageServiceProvider

Build Status Latest Stable Version Total Downloads

This is a service provider of TwiggedSwiftMessageBuilder for Silex.

Requirements

  • PHP 5.3+

Getting started

First add this dependency into your composer.json:

{
    "require": {
        "qckanemoto/twigged-swiftmessage-service-provider": "1.0.*@dev"
    },
    "minimum-stability": "dev"
}

And enable this service provider in your application. Please notice that you must register both TwigServiceProvider and SwiftmailerServiceProvider on ahead.

$app->register(new TwigServiceProvider());
$app->register(new SwiftmailerServiceProvider());
$app->register(new \Qck\Silex\Provider\TwiggedSwiftMessageServiceProvider());

Then you can build Swift_Message object via twig template.

$message = $app['twigged_message']->buildMessage('email.txt.twig');
$message->setTo('[email protected]');
$app['mailer']->send($message);

See more detailed documentation here.

Use submitted form data in Twig template

This service provider provides one additional feature to use submitted form data in Twig template easily. $app['twigged_swiftmessage.form_handler'] allows you to extract data array from Form object.

Labels and values of each fields can be used as below:

  • {{ form.[field-name].label }}
  • {{ form.[field-name].value }}

For example:

{# email.txt.twig #}

{% block from %}{{ form.email.value }}{% endblock %}
{% block from_name %}{{ form.name.value }}{% endblock %}
{% block to %}[email protected]{% endblock %}

{% block subject %}[Contact] {{ form.summary.value }}{% endblock %}

{% block body %}
{% for item in form %}
----------------------------------------------------------------------
{{ item.label }}: {{ item.value }}
{% endfor %}
----------------------------------------------------------------------
{% endblock %}
// in your controller.

$form->handleRequest($request);
if ($form->isValid()) {
    $array = $app['twigged_message.form_handler']->getDataArray($form);
    $message = $app['twigged_message']->buildMessage('email.txt.twig', array('form' => $array));
    $app['mailer']->send($message);
}

Offcourse you also can access to your custom field type as below:

  • {{ form.[parent-field].[child-field].label }}
  • {{ form.[parent-field].[child-field].value }}

Enjoy!

See more detailed documentation here.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.