Block cache with a twig

I switched from Phptal to Twig: a very good experience. However, in phptal, I made "tal: cache" to cache some blocks of code ... with Twig, how can I do this?

+4
source share
2 answers

You can cache blocks in a branch using this extension:

https://github.com/asm89/twig-cache-extension

It allows you to cache template blocks based on TTL, cache key changes, etc.

+5
source

There is no explicit caching of certain blocks in a branch.

But twig caches intermediate code created from templates when it is not in debug mode.

Look here:
http://symfony.com/doc/current/book/templating.html#twig-template-caching

This is in the context of symfony, but I think it will also work autonomously.
Then you can specify it with the following values: Instruction Twig_Environment:

'cache' => 'cache/templates', // the place to cache to 'auto_reload' => true //reload template when changes are detected 

Look here:
http://twig.sensiolabs.org/doc/api.html#environment-options

+3
source

Source: https://habr.com/ru/post/1436978/


All Articles