Skip to content
This repository was archived by the owner on Feb 17, 2022. It is now read-only.

7.x 2.x twig recipes

Andy Truong edited this page Jan 8, 2014 · 17 revisions

Render View with template:

{{ 'view_name'|drupalView({template: '@my_module/templates/views/view_name.html.twig'}) }}

Cache

Cache function call

{# Simple function #}
{% set options = { cache_id: 'atestTwigCache:1' } %}
{{ 'atest_base_hello' | cache(options) }}

{# Static method #}
{% set options = { cache_id: 'atestTwigCache:1' } %}
{{ 'At_Base_Test_Class::helloStatic' | cache(options) }}

{# Callback with argument #}
{% set callback = { callback: 'atest_base_hello', arguments: ['Andy Truong'] } %}
{{ callback | cache(options) }}

Cache service call

{% set options = { cache_id: 'atestTwigCache:1' } %}
{{ 'atest_base.service_1:hello' | cache(options) }}

Clone this wiki locally