Tuesday, June 28, 2011

Capifony: Send an email after deployment

First, thanks to @cordoval at the #symfony channel for suggesting me to use a symfony2 command to do this.

To use this command you must have the SwiftmailerBundle enabled. More info here.

This is a simple Symfony2 command to send an email, you should add it to a "Command" directory inside your bundle and replace the namespace to fit your project bundle:

The email body is just "test" but you can probably modified it you need to.

Test the new command by running the following:

php app/console capifony:sendemail emailfrom@server.com emailto@server.com subject

Finally, this task will run the capifony:sendemail command after the deployment is complete, be sure to add it to your Capifony script:

Want to learn more about Symfony2 console/command-line commands?



Sunday, June 19, 2011

How to enable the twig truncate filter (Text extension) in Symfony2 beta5

Problem ?

In previous versions of Symfony2, to enable a extension you needed to add the Text and/or Debug extensions to an "extensions" array in your config.yml

# Twig Configuration
debug: %kernel.debug%
strict_variables: %kernel.debug%
- twig.extension.debug
- twig.extension.text

This was because the extensions were added to the twig.xml file

<service id="twig.extension.text" class="Twig_Extensions_Extension_Text" public="false">

<service id="twig.extension.debug" class="Twig_Extensions_Extension_Debug" public="false">

But, this is the way to do it now :

// app/config/config.yml
class: Twig_Extensions_Extension_Text
- { name: twig.extension }

I spent some time trying to figure out how to do it, so I hope it helps someone.