entea/silex-twig-simple-asset-extension

Silex的简单twig资产函数

v1.0.1 2015-01-14 09:28 UTC

This package is not auto-updated.

Last update: 2024-09-22 03:34:09 UTC


README

使用说明

require_once __DIR__ . '/silex.phar';

$app = new Silex\Application();
$app['debug'] = true;
$app['autoloader']->registerNamespaces(array('Entea'   => __DIR__.'/src'));
$app->register(
    new Silex\Provider\TwigServiceProvider(),
    array(
         'twig.path' => __DIR__ . '/views',
         'twig.class_path' => __DIR__ . '/vendor/twig/lib',
    )
);

/* @var Twig_Environment $twig */
$twig = $app['twig'];
$twig->addExtension(new \Entea\Twig\Extension\AssetExtension($app));

$app->get('/', function() use (&$app)
    {
        return $app['twig']->render('index.html.twig', array());
    });

$app->run();

然后,在你的twig文件中

{{asset('/style/hello.css')}}

或者使用特定版本覆盖全局版本

{{asset('/style/hello.css', '1.2')}}

属性

  • asset.directory: 您的资产目录
  • asset.version: 您的资产全局版本(默认:1.0)

安装

通过composer

require: "entea/silex-twig-simple-asset-extension": "dev-master"

或者

require: "entea/silex-twig-simple-asset-extension": "v1.0.1"

或者简单地检出此仓库 :)