This repository was archived by the owner on Feb 17, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
7.x 2.x twig recipes
Andy Truong edited this page Mar 3, 2014
·
17 revisions
Twig compiled templates are cached by default. To auto refresh the compiled template, in settings.php, add this line:
defined('AT_DEBUG', TRUE);
Do not enable this on production sites.
{# call: Class_Name::getValue() #}
{{ 'Is same to: ' ~ fn__at_container('server.name').value() }}
{{ fn__at_container('server.name').getValue() }}
{{ attribute(get_defined_vars(), 'context')|kpr }}
{{ 'view_name'|drupalView({template: '@my_module/templates/views/view_name.html.twig'}) }}
To minimize your time on view template, just extends to default view template:
{% extends '@at_base/templates/views_view.html.twig' %}
{% block debug %}
{{ attribute(get_defined_vars(), 'context')|dsm }}
{% endblock %}
{% set o = { template: '@atest_base/templates/entity/user.html.twig' } %}
{{ 'user:1'|drupalEntity(o) }}
{# 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) }}
{% set options = { cache_id: 'atestTwigCache:1' } %}
{{ 'atest_base.service_1:hello' | cache(options) }}
A page for you to debug Twig templates.
{# Call trim() #}
{{ fn__trim(' Drupal 7 ') }}
{{ ' Drupal 7 '|fn__trim }}
{# Call At_Base_Test_Class::helloStatic() #}
{{ 'Drupal 8'|At_Base_Test_Class__class__helloStatic }}
{{ At_Base_Test_Class__class__helloStatic('Drupal 8') }}
{# $obj = new At_Base_Test_Class('PHP'); $obj->helloProperty(); #}
{{ 'PHP'|At_Base_Test_Class__obj__helloProperty }}
{{ At_Base_Test_Class__obj__helloProperty('PHP') }}
{# Drupal\atest_base\Service_1::helloStatic('Namespace') #}
{{ 'Namespace'|ns_Drupal__atest_base__Service_1__class__helloStatic }}
{{ ns_Drupal__atest_base__Service_1__class__helloStatic('Namespace') }}
___ ___________ _ _
/ _ \_ _| ___ \ | | | |
/ /_\ \| | | |_/ / __ _ ___ ___ _ __ ___ ___ __| |_ _| | ___
| _ || | | ___ \/ _` / __|/ _ \ | '_ ` _ \ / _ \ / _` | | | | |/ _ \
| | | || | | |_/ / (_| \__ \ __/_| | | | | | (_) | (_| | |_| | | __/
\_| |_/\_/ \____/ \__,_|___/\___(_)_| |_| |_|\___/ \__,_|\__,_|_|\___|
- Caching
- Twig template
- twig Service
- twig_string Service
- Recipes
- Extends
- Easy Block
- Easy Routing
- Easy Breadcrumb
- Entity Template
- Drush Commands:
- Functions:
- Misc
- Status
- Tools for Development enviroment
- /devel/php improved
- /at/sql
- /at/twig
- Kint integration