PHPackages                             maxmattone/to-twig - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. maxmattone/to-twig

ActiveApplication[Templating &amp; Views](/categories/templating)

maxmattone/to-twig
==================

A script to convert smarty template engine to twig

01PHP

Since Aug 23Pushed 6y agoCompare

[ Source](https://github.com/mattonem/to-twig)[ Packagist](https://packagist.org/packages/maxmattone/to-twig)[ RSS](/packages/maxmattone-to-twig/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependenciesVersions (1)Used By (0)

PHP Smarty to Twig Converter
============================

[](#php-smarty-to-twig-converter)

toTwig is an utility to convert smarty template engine to twig template engine.

Installation
------------

[](#installation)

### Locally

[](#locally)

Download the [`toTwig.phar`](https://raw.github.com/sankarsuda/toTwig/master/toTwig.phar) file and store it somewhere on your computer.

### Globally (manual)

[](#globally-manual)

You can run these commands to easily acces `toTwig` from anywhere on your system:

```
$ sudo wget https://raw.github.com/sankarsuda/toTwig/master/toTwig.phar -O /usr/local/bin/toTwig

```

or with curl:

```
$ sudo curl https://raw.github.com/sankarsuda/toTwig/master/toTwig.phar -o /usr/local/bin/toTwig

```

then:

```
$ sudo chmod a+x /usr/local/bin/toTwig

```

Then, just run `toTwig`

Update
------

[](#update)

### Locally

[](#locally-1)

The `self-update` command tries to update toTwig itself:

```
$ php toTwig.phar self-update

```

### Globally (manual)

[](#globally-manual-1)

You can update toTwig through this command:

```
$ sudo toTwig self-update

```

Usage
-----

[](#usage)

The `convert` command tries to fix as much coding standards problems as possible on a given file or directory:

```
`php toTwig.phar convert /path/to/dir`
`php toTwig.phar convert /path/to/file`

```

The `--converters` option lets you choose the exact converters to apply (the converter names must be separated by a comma):

```
`php toTwig.phar convert /path/to/dir --converters=for,if,misc`

```

You can also blacklist the converters you don't want if this is more convenient, using `-name`:

```
`php toTwig.phar convert /path/to/dir --converters=-for,-if`

```

A combination of `--dry-run`, `--verbose` and `--diff` will display summary of proposed changes, leaving your files unchanged.

All converters apply by default.

Choose from the list of available converters:

- **include** Convert smarty include to twig include
- **assign** Convert smarty {assign} to twig {% set foo = 'foo' %}
- **variable** Convert smarty variable {$var.name} to twig {{ var.name }}
- **comment** Convert smarty comments {\* \*} to twig {# #}
- **misc** Convert smarty general tags like {ldelim} {rdelim} {literal}
- **if** Convert smarty if/else/elseif to twig
- **for** Convert foreach/foreachelse to twig

The `--config` option customizes the files to analyse, based on some well-known directory structures:

```
`# For the Symfony 2.1 branch`
`php toTwig.phar convert /path/to/sf21 --config=sf21`

```

Choose from the list of available configurations:

- **default** A default configuration

The `--dry-run` option displays the files that need to be fixed but without actually modifying them:

```
`php toTwig.phar convert /path/to/code --dry-run`

```

Instead of using command line options to customize the converter, you can save the configuration in a `.php_st` file in the root directory of your project. The file must return an instance of `toTwig\ConfigInterface`, which lets you configure the converters, the files, and directories that need to be analyzed:

```
