PHPackages                             junker/smarty-service-provider - 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. junker/smarty-service-provider

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

junker/smarty-service-provider
==============================

Smarty service provider for silex

0.4.0(2y ago)161MITPHPPHP &gt;=7.1.0

Since May 22Pushed 2y ago1 watchersCompare

[ Source](https://github.com/Junker/Silex_SmartyServiceProvider)[ Packagist](https://packagist.org/packages/junker/smarty-service-provider)[ Docs](https://github.com/junker/Silex_SmartyServiceProvider.git)[ RSS](/packages/junker-smarty-service-provider/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (7)Dependencies (2)Versions (8)Used By (0)

SmartyServiceProvider
=====================

[](#smartyserviceprovider)

The *SmartyServiceProvider* provides integration with the \[Smarty\] () template engine.

Parameters
----------

[](#parameters)

- **smarty.dir** (string, optional): Path to the directory containing Smarty distribution (a one with folders libs and demo). If not given, provider assumes, that smarty class is already loaded.
- **smarty.instance** (\\Smarty, optional): An instance of Smarty class. If not given, will be created by the provider.
- **smarty.options** (array, optional): An associative array of smarty class variables to set. Check out the \[Smarty documentation\] () for more information.
- **smarty.configure** (callable, optional): A callable which takes one argument - Smarty class instance. It is called during provider's register() method. You can use this option to make some custom smarty configuration, for example.

Services
--------

[](#services)

- **smarty**: The `Smarty` instance. The main way of interacting with Smarty.

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

[](#installation)

The best way to install Smarty Trait is to use a [Composer](https://getcomposer.org/download):

```
composer require junker/smarty-service-provider

```

Registering
-----------

[](#registering)

Make sure you place a copy of \[Smarty\] () in the `vendor/Smarty` directory:

```
use Junker\Silex\Provider\SmartyServiceProvider;
define('SMARTY_PATH', __DIR__ . '/../../../../vendor/Smarty');

$app->register(new SmartyServiceProvider(), array(
          'smarty.dir' => SMARTY_PATH,
          'smarty.options' => array(
                'template_dir' => SMARTY_PATH . '/demo/templates',
                'compile_dir' => SMARTY_PATH . '/demo/templates_c',
                'config_dir' => SMARTY_PATH . '/demo/configs',
                'cache_dir' => SMARTY_PATH . '/demo/cache',),));
```

**Note:**

Smarty is not compiled into the `silex.phar` file. You have to add your own copy of \[Smarty\] () to your application.

Usage
-----

[](#usage)

The Smarty provider provides a `smarty` service:

```
$app->get('/hello/{name}', function ($name) use ($app) {
    return $app['smarty']->display('hello.tpl', [
        'name' => $name,
    ]);
});
```

This will render a file named `hello.tpl` in the configured templates folder you passed in `smarty.options`.

In any Smarty template, the `app` variable refers to the Application object. So you can access any services from within your view. For example to access `$app['request']->getHost()`, just put this in your template:

```
{$app.request->getHost()}

```

Get new smarty instance with same smarty.options:

```
$smarty2 = $app['smarty.new_instance']();
```

Traits:

```
class Application extends \Silex\Application
{
	use \Junker\Silex\Application\SmartyTrait;
}

$app->render('hello.tpl', [
        'name' => $name,
    ]);
```

Template usage
--------------

[](#template-usage)

```
{path _name='app.login'}
same as $app['url_generator']->generate('app.login');

{path _name='app.product' id=11}
same as $app['url_generator']->generate('app.product', ['id' => 11]);

{url _name='app.login'}
same as $app['url_generator']->generate('app.login', UrlGeneratorInterface::ABSOLUTE_URL);

{trans _name='err.access_forbidden'}
same as $app['translator']->trans('err.access_forbidden');

{trans _name='warn.my_city' city='London'}
same as $app['translator']->trans('warn.my_city', ['%city%' => 'London']);

{trans}hello{/trans}
same as $app['translator']->trans('hello');

{transChoice _name='days' _count=5}
same as $app['translator']->transChoice('days', 5, ['%count%' => 5]);
```

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 52.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~300 days

Recently: every ~367 days

Total

7

Last Release

745d ago

PHP version history (2 changes)0.1.0PHP &gt;=5.3.2

0.4.0PHP &gt;=7.1.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1144095?v=4)[Dmitry Kosenkov](/maintainers/Junker)[@Junker](https://github.com/Junker)

---

Top Contributors

[![FractalizeR](https://avatars.githubusercontent.com/u/318489?v=4)](https://github.com/FractalizeR "FractalizeR (10 commits)")[![Junker](https://avatars.githubusercontent.com/u/1144095?v=4)](https://github.com/Junker "Junker (7 commits)")[![jarolu](https://avatars.githubusercontent.com/u/1580164?v=4)](https://github.com/jarolu "jarolu (2 commits)")

---

Tags

extensionsmartysilexsilex-extension

### Embed Badge

![Health badge](/badges/junker-smarty-service-provider/health.svg)

```
[![Health](https://phpackages.com/badges/junker-smarty-service-provider/health.svg)](https://phpackages.com/packages/junker-smarty-service-provider)
```

###  Alternatives

[noiselabs/smarty-bundle

This Symfony bundle provides integration for the Smarty3 template engine.

53194.4k1](/packages/noiselabs-smarty-bundle)[latrell/smarty

This package lets you run Smarty3 on Laravel5 elegantly.

127.0k](/packages/latrell-smarty)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
