PHP code example of junker / smarty-service-provider

1. Go to this page and download the library: Download junker/smarty-service-provider library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

junker / smarty-service-provider example snippets


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',),));

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



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

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

$app->render('hello.tpl', [
        'name' => $name,
    ]);
smarty
{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]);