eglobal/template-cache-bundle
Composer 安装命令:
composer require eglobal/template-cache-bundle
包简介
Symfony template caching functionality.
关键字:
README 文档
README
Installation
Install this bundle using Composer. Add the following to your composer.json:
{
"require": {
"eglobal/template-cache-bundle": "~1.0"
}
}
Register bundle in the app/AppKernel.php:
public function registerBundles() { $bundles = [ // ... new EGlobal\Bundle\TemplateCacheBundle\EGlobalTemplateCacheBundle(), ]; }
Update config:
parameters: locales: - en - es - de # If using Assetic, add the bundle to the config assetic: bundles: - EGlobalTemplateCacheBundle eglobal_template_cache: # Locales to be cached locales: "%locales%" # Cache only exposed routes exposed_routes_only: false # Public directory to store cached templates cache_dir: '%kernel.root_dir%/../web/templates' # Public prefix of cached templates public_prefix: '/templates' # Directories to search cacheable templates in root_dirs: - "@AcmeFooBundle/Controller" - "@AcmeBarBundle/Controller/Cacheable"
Example usage
Mark controller routes as cacheable
<?php namespace Acme\FooBundle\Controller; use EGlobal\Bundle\TemplateCacheBundle\Annotation\CacheableTemplate; use Symfony\Component\Routing\Annotation\Route; use Symfony\Bundle\FrameworkBundle\Controller\Controller; class MyController extends Controller { /** * @Route(methods={"GET"}, path="/my/foo.html", name="my.template.foo", options={"expose"=true}) * @CacheableTemplate("AcmeFooBundle:Template:foo.html.twig") */ public function fooAction() { // Your controller logic } /** * @Route(methods={"GET"}, path="/my/bar.svg", name="my.template.bar", options={"expose"=true}) * @CacheableTemplate("AcmeFooBundle:Template:bar.svg.twig") */ public function barAction() { // Your controller logic } }
Dump templates into cache files
$ php bin/console eglobal:template-cache:dump
Add assets to your template
... <head> <script type="text/javascript" src="{{ asset('bundles/eglobaltemplatecache/js/template-cache.js') }}"></script> {% if not app.debug %} <script type="text/javascript" src="{{ asset(jsTemplateMapFileName(app.request.locale)) }}"></script> {% endif %} </head> ...
Use cacheable template paths in your code
// This will return some path like '/templates/en/f9d15a8be554432de01799a8c51d123f.html' var fooCachedUrl = TemplateCache.get('my.template.foo'); // This will return some path like '/templates/en/f9d15a8be554432de01799a8c51d123f.svg' var barCachedUrl = TemplateCache.get('my.template.bar');
统计信息
- 总下载量: 3.25k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-01-19