{"id":20036984,"url":"https://github.com/antistatique/drupal-bamboo-twig","last_synced_at":"2025-05-05T06:30:35.056Z","repository":{"id":47771238,"uuid":"85471768","full_name":"antistatique/drupal-bamboo-twig","owner":"antistatique","description":"Several Twig extensions with some useful functions and filters that can improve development experience.","archived":false,"fork":false,"pushed_at":"2025-04-23T07:16:04.000Z","size":424,"stargazers_count":14,"open_issues_count":4,"forks_count":2,"subscribers_count":11,"default_branch":"6.0.x","last_synced_at":"2025-04-23T08:25:04.986Z","etag":null,"topics":["drupal","drupal-8","drupal-module"],"latest_commit_sha":null,"homepage":"https://www.drupal.org/project/bamboo_twig","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/antistatique.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2017-03-19T11:46:35.000Z","updated_at":"2025-04-23T07:16:02.000Z","dependencies_parsed_at":"2025-02-14T09:28:23.014Z","dependency_job_id":"1dfb169c-d61f-4a1d-a84a-dbbbd4f756f4","html_url":"https://github.com/antistatique/drupal-bamboo-twig","commit_stats":null,"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antistatique%2Fdrupal-bamboo-twig","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antistatique%2Fdrupal-bamboo-twig/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antistatique%2Fdrupal-bamboo-twig/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antistatique%2Fdrupal-bamboo-twig/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/antistatique","download_url":"https://codeload.github.com/antistatique/drupal-bamboo-twig/tar.gz/refs/heads/6.0.x","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252451315,"owners_count":21749917,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["drupal","drupal-8","drupal-module"],"created_at":"2024-11-13T10:17:43.983Z","updated_at":"2025-05-05T06:30:35.049Z","avatar_url":"https://github.com/antistatique.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# BAMBOO TWIG\n\nAll the Twig features you missed until now.\n\nA Drupal powered module.\n\n|       Tests-CI        |        Style-CI         |                                                                        Downloads                                                                         |                                                                        Releases                                                                        |\n|:----------------------:|:-----------------------:|:--------------------------------------------------------------------------------------------------------------------------------------------------------:|:------------------------------------------------------------------------------------------------------------------------------------------------------:|\n| [![Build Status](https://github.com/antistatique/drupal-bamboo-twig/actions/workflows/ci.yml/badge.svg)](https://github.com/antistatique/drupal-bamboo-twig/actions/workflows/ci.yml) | [![Code styles](https://github.com/antistatique/drupal-bamboo-twig/actions/workflows/styles.yml/badge.svg)](https://github.com/antistatique/drupal-bamboo-twig/actions/workflows/styles.yml) | [![Downloads](https://img.shields.io/badge/downloads-6.0.1-green.svg?style=flat-square)](https://ftp.drupal.org/files/projects/bamboo_twig-6.0.1.tar.gz) | [![Latest Stable Version](https://img.shields.io/badge/release-v6.0.1-blue.svg?style=flat-square)](https://www.drupal.org/project/bamboo_twig/releases) |\n\nThe Bamboo Twig module provides some Twig extensions with some useful functions\nand filters aimed to improve the development experience.\n\nBamboo Twig has a lot of advantages and brings a lot of new features to the Twig landscape of Drupal 8.\nIt boosts performance by using lazy loading, improves the code quality\nwith automated workflow. It also includes automated unit and kernel tests\nto ensure stability.\n\n## Use Bamboo Twig if\n\n  - You need to \"Format dates using Drupal I118n\".\n  - You need to \"Render a Block\".\n  - You need to \"Render a Region\".\n  - You need to \"Render an Entity with view mode\".\n  - You need to \"Load an Entity\".\n  - You need to \"Render a Field\".\n  - You need to \"Retrieve the current user\".\n  - You need to \"Check permissions or roles\".\n  - You need to \"Bubble Cache Metadata from Twig\".\n  - You need to \"Render a Form\".\n  - You need to \"Deal with image styles\".\n  - You need to \"Use Token\".\n  - You need to \"Create an absolute URL from a theme\".\n  - You need to \"Retrieve the Extension file from given mimeType\".\n  - You want to use a twig module which is design to works on multilingual websites.\n  - You want to use a twig module that follows all the best practices.\n  - You want to use a twig module that ensure stability with tests.\n  - You want to use a twig module that will be compatible Drupal 9.\n\nBamboo Twig can do a lot more than that, but perhaps these are some of the\nobvious uses of Bamboo Twig.\n\n## Performances\n\nFor performances reasons, Bamboo Twig has been split into multiple sub-modules\nfor each topic he provides Twigs.\n\n## Bamboo Twig versions\n\nBamboo Twig is available for Drupal 8, Drupal 9, Drupal 10 \u0026 Drupal 11 !\n\n- If you are running Drupal `11.x`, use Bamboo Twig `6.0.x`.\n- If you are running Drupal `10.x`, use Bamboo Twig `6.0.x`.\n- If you are running Drupal `9.x`, use Bamboo Twig `5.x`.\n- If you are running Drupal `8.8.x`, use Bamboo Twig `5.0`.\n- If you are running Drupal `8.7.x`, use Bamboo Twig `4.x`.\n\nIf you need some help to upgrade from the version `8.x-1.x` to `8.x-2.x` check\n[the guide](https://www.drupal.org/docs/8/modules/bamboo-twig/migrate-from-8x-1x-to-8x-2x#comment-12051399) about it.\n\nIn the case you are looking for the documentation of version `8.x-1.x`, check\nthe [README.md](https://github.com/antistatique/drupal-bamboo-twig/blob/8.x-1.x/README.md)\nor the previous [project page](https://www.drupal.org/node/2884024).\n\nThe version `8.x-2.1` is not compatible with Drupal `8.4.x`.\nDrupal `8.4.x` brings some breaking change with tests and so you\nmust upgrade to `8.x-3.x` version of **Bamboo Twig**.\n\nThe version `8.x-5.x` is not compatible with Drupal `8.7.x`.\nDrupal `8.8.x` brings some breaking change with tests and so you\nmust upgrade to `8.x-3.x` version of **Bamboo Twig**.\n\n## Which version should I use?\n\n| Drupal Core | Bamboo Twig |\n|:-----------:|:-----------:|\n|    8.0.x    |     1.x     |\n|    8.4.x    |     2.x     |\n|    8.7.x    |     4.x     |\n|    8.8.x    |     5.0     |\n|    8.9.x    |     5.0     |\n|     9.x     |     5.x     |\n|    10.x     |    6.0.x    |\n|    11.x     |    6.0.x    |\n\n## Dependencies\n\nThe Drupal 8, Drupal 9, Drupal 10 \u0026 Drupal 11 version of Bamboo Twig requires nothing !\nFeel free to use it.\n\n## Similar modules\n\nAt first sight, Bamboo Twig offers similar functionality to the following modules,\nalthough Bamboo Twig will normalize the way you use twig in your Drupal project,\nthus reducing the need to install a bunch of extra modules.\n\nPlus, it adds a lots of functionality, ensures stability with tests, includes automated\nquality control and is totally open to contribution via [Github](https://github.com/antistatique/drupal-bamboo-twig) or [Drupal Issue Queue](https://www.drupal.org/project/issues/bamboo_twig).\n\nFinally, Bamboo Twig follows all the best practices of Drupal \u0026 Symfony to ensure\ncompatibility with next Drupal releases.\n\n  - Only expose a set of Renderer functions \u0026 filters [Twig Tweak](https://www.drupal.org/project/twig_tweak).\n  - Output clean Twig debug [Twig Clean Debug](https://www.drupal.org/project/twig_clean_debug).\n  - Define and expose self-contained UI patterns [UI Patterns](https://www.drupal.org/project/ui_patterns).\n  - Provides the [raulfraile/ladybug](https://github.com/raulfraile/ladybug) Dumper [Devel Ladybug](https://www.drupal.org/project/devel_ladybug).\n  - Add attributes to link() item.url's [Twig Link Attributes](https://www.drupal.org/project/twig_link_attributes).\n  - Reuse small self contained parts from theme templates [Partial](https://www.drupal.org/project/partial).\n  - Embed Views [TVE](https://www.drupal.org/project/tve).\n  - Port Twig Extensions to Drupal [Twig Extensions](https://www.drupal.org/project/twig_extensions).\n  - Use a set of tools to debug Drupal [LGP](https://www.drupal.org/project/lgp).\n  - Use a set of tools to deal with render arrays [Twig Renderable](https://www.drupal.org/project/twig_renderable).\n  - Get partial data from field render arrays [Twig Field Value](https://www.drupal.org/project/twig_field_value).\n  - Execute PHP code from Twig - **Do not use this module** - [Twig PHP](https://www.drupal.org/project/twig_php).\n\n## Supporting organizations\n\nThis project is sponsored by [Antistatique](https://www.antistatique.net), a Swiss Web Agency.\nVisit us at [www.antistatique.net](https://www.antistatique.net) or\n[Contact us](mailto:info@antistatique.net).\n\n## Getting Started\n\nWe highly recommend you to install the module using `composer`.\n\n```bash\n$ composer require drupal/bamboo_twig\n```\n\n## Bamboo Twig Extensions\n\n**Internationalization**\n\n`date|bamboo_i18n_format_date('medium')` returns a date string in the correct locality.\n\n- `date` string - date, timestamp, DrupalDateTimePlus, DateTimePlus or DateTime\n- `type` string (optional) - The format to use, one of the built-in formats: 'short', 'medium', 'long'. Use 'custom' to use `format`.\n- `format` string (optional) - PHP date format string suitable for input to date()\n- `timezone` string (optional) - Time zone identifier, as described on [php.net/manual/timezones.php](http://php.net/manual/timezones.php), defaults to the timezone used to display the page.\n- `langcode` string (optional) - defaults to current interface language.\n\n```twig\n{# Print the formatted date using Drupal i18n. #}\n\u003cp\u003eFormat date:\u003c/p\u003e\n{{ node.changed.value|bamboo_i18n_format_date('medium') }}\u003cbr\u003e\n{{ node.changed.value|bamboo_i18n_format_date('custom', 'Y-m-d') }}\n```\n\n`bamboo_i18n_current_lang()` returns the current lang iso code.\n\n```twig\n{# Print the current language ID. #}\n\u003cp\u003eCurrent lang:\u003c/p\u003e\n{{ bamboo_i18n_current_lang() }}\n```\n\n`entity|bamboo_i18n_get_translation` returns the translated entity.\n\n- `langcode` string (optional) - defaults to current interface language.\n\n```twig\n{# Get the French translation of an entity #}\n\u003cp\u003eFrench title of entity:\u003c/p\u003e\n\u003cp\u003e{{ entity|bamboo_i18n_get_translation('fr').title.value }}\u003c/p\u003e\n\u003cp\u003eTitle of entity using the current interface language:\u003c/p\u003e\n\u003cp\u003e{{ entity|bamboo_i18n_get_translation.title.value }}\u003c/p\u003e\n```\n\n`bamboo_load_entity(entity_type, id)` returns the loaded entity. Use if you don't already have a `Drupal\\Core\\Entity\\EntityInterface` object.\n\n```twig\n{# Load the entity node with nid 1 #}\n{% set node = bamboo_load_entity('node', 1) %}\n{# Then get the German translation of node #}\n\u003cp\u003eGerman title of entity:\u003c/p\u003e\n\u003cp\u003e{{ node|bamboo_i18n_get_translation('de').title.value }}\u003c/p\u003e\n```\n\n**Files**\n\n`filetype|bamboo_file_extension_guesser` returns the extension of a file based on its\nmimeType.\n\n- `mimeType` string\n\n```twig\n{# Print the extension of the `application/pdf` mimeType #}\n{{ 'application/pdf'|bamboo_file_extension_guesser }}\n```\n\n`bamboo_file_url_absolute(uri)` returns the absolute URL of a given URI\nor path to a file.\n\n- `uri` string - URI or string path to a file.\n\n```twig\n{# Print the absolute URL to access `image.jpg` #}\n{{ bamboo_file_url_absolute('public://image.jpg') }}\n```\n\n**Paths**\n\n`bamboo_path_system(type, item)` returns the relative URL of a system entity.\n\n- `type` string - must be either of 'core', 'profile', 'module', 'theme' or 'theme_engine'.\n- `item` string\n\n```twig\n{# Print the relative URL of the system entity `theme` named `stable` #}\n{{ bamboo_path_system('theme', 'starterkit_theme') }}\n```\n\n**Loaders**\n\n`bamboo_load_currentuser()` returns the User object of the current logged user.\n\n```twig\n{# Load the current user #}\n{% set user = bamboo_load_currentuser() %}\n```\n\n`bamboo_load_entity(entity_type, id, langcode)` returns a EntityInterface object\nof the requested entity.\n\n- `entity_type` string\n- `id` int (optional)\n- `langcode` string (optional) - defaults to current context language\n\n```twig\n{# Load the entity node with nid 1 #}\n{% set node = bamboo_load_entity('node', 1) %}\n```\n\nKeep in mind, when loading an entity it will fetch it in the current context language.\nWhen you access it directly through a *EntityReferenceField* or a *Paragraph*\n(e.g. `node.field_referenced_tags.entity`), the entity is always loaded in its original language.\n(it won't be loaded in the current context language or in the entity language)\nYou should then use the `|bamboo_i18n_get_translation` filter to make sure you have the\nentity displayed in another language.\n\n```twig\n{# Load the entity node with nid 1 #}\n{% set node = bamboo_load_entity('node', 1) %}\n{# Display the entity title in the current context lang (page language) #}\n{{ node.title.value }}\n{# Display the referenced entity name in its original lang #}\n{{ node.field_referenced_tags.entity.name.value }}\n{# Display the referenced entity name in the current context lang (page language) #}\n{{ node.field_referenced_tags.entity|bamboo_i18n_get_translation.name.value }}\n```\n\n`bamboo_load_entity_revision(entity_type, revision_id, langcode)` returns a EntityInterface object\nof the requested entity revision.\n\n- `entity_type` string\n- `revision_id` int (optional)\n- `langcode` string (optional) - defaults to current context language\n\n```twig\n{# Load the entity revision node with revision ID 1 #}\n{% set node = bamboo_load_entity_revision('node', 1) %}\n```\n\nKeep in mind, when loading an entity it will fetch it in the current context language.\nWhen you access it directly through a *EntityReferenceField* or a *Paragraph*\n(e.g. `node.field_referenced_tags.entity`), the entity is always loaded in its original language.\n(it won't be loaded in the current context language or in the entity language)\nYou should then use the `|bamboo_i18n_get_translation` filter to make sure you have the\nentity displayed in another language.\n\n```twig\n{# Load the entity revision node with revision ID 1 #}\n{% set node = bamboo_load_entity_revision('node', 1) %}\n{# Display the entity title in the current context lang (page language) #}\n{{ node.title.value }}\n{# Display the referenced entity name in its original lang #}\n{{ node.field_referenced_tags.entity.name.value }}\n{# Display the referenced entity name in the current context lang (page language) #}\n{{ node.field_referenced_tags.entity|bamboo_i18n_get_translation.name.value }}\n```\n\n`bamboo_load_field(field, entity_type, id)` returns a FieldItemListInterface object of the requested field.\n\n- `field` string\n- `entity_type` string\n- `id` int\n\n```twig\n{# Load the title of node 1 with nid 1 #}\n{% set title = bamboo_load_field('title', 'node', 1) %}\n```\n\nKeep in mind, loading a field with `bamboo_load_field()` will fetch it in the\ncurrent context language.\nWhen you access it directly through a *EntityReferenceField* or *Paragraph*,\nthe entity is always in its original language\n(it won't be loaded in the current context language or in the entity language).\nYou should then use the `|bamboo_i18n_get_translation` filter to make sure you have the\nentity displayed in another language.\n\n```twig\n{# Load the entity node with nid 1 #}\n{% set title = bamboo_load_field('title', 'node', 1) %}\n{# Display the entity title in the current context lang (page language) #}\n{{ title.value }}\n{% set tags = bamboo_load_field('field_tags', 'node', 1) %}\n{# Display the entity name in his original lang #}\n{{ tags.entity.name.value }}\n{# Display the entity name in the current context lang (page language) #}\n{{ tags.entity|bamboo_i18n_get_translation.name.value }}\n```\n\n`bamboo_load_image(path)` returns a ImageInterface object\nof the requested image.\n\n- `path` string - The path or URI to the original image.\n\n```twig\n{# Load image with URI `public://antistatique.jpg` #}\n{% set image = bamboo_load_image('public://antistatique.jpg') %}\n```\n\n**Render**\n\n`bamboo_render_block(block_name, params, wrapper)` returns a render array of the\nspecified block (works only for Plugin Block).\n\n- `block_name` string\n- `params` array (optional)\n- `wrapper` bool (optional) Whether it use block template for rendering. Defaults: FALSE.\n\n```twig\n{# Render the `system_powered_by_block` block #}\n{{ bamboo_render_block('system_powered_by_block') }}\n```\n\nIn case you want to render a Block Entity,\nyou have to use `bamboo_render_entity()`. See example below.\n\n`bamboo_render_entity(entity_type, id, view_mode, langcode)` returns a render array of the specified\nentity type. Can be rendered a specific `view_mode`.\n\n- `entity_type` string\n- `id` int (optional)\n- `view_mode` string (optional) - machine name of the view mode\n- `langcode` string (optional) - defaults to current language\n\n```twig\n{# Render node with nid 1 #}\n{{ bamboo_render_entity('node', 1) }}\n\n{# Render the teaser of node with nid 2 #}\n{{ bamboo_render_entity('node', 2, 'teaser') }}\n\n{# Render Block entity #}\n{{ bamboo_render_entity('block', 'stark_messages') }}\n```\n\n`bamboo_render_entity_revision(entity_type, revision_id, view_mode, langcode)` returns a render array of the specified\nentity revision type. Can be rendered a specific `view_mode`.\n\n- `entity_type` string\n- `revision_id` int (optional)\n- `view_mode` string (optional) - machine name of the view mode\n- `langcode` string (optional) - defaults to current language\n\n```twig\n{# Render node with revision id 1 #}\n{{ bamboo_render_entity_revision('node', 1) }}\n\n{# Render the teaser of node with revision id 2 #}\n{{ bamboo_render_entity_revision('node', 2, 'teaser') }}\n```\n\n`bamboo_render_form(module, formName)` returns a render array of the specified Form.\n\n- `module` string\n- `formName` string\n- `params` mixed (optional)\n\n```twig\n{# Render a the CronForm #}\n{{ bamboo_render_form('system', 'CronForm') }}\n```\n\n`bamboo_render_menu(menu_name, level, depth)` returns a render array of the specified menu.\n\n- `menu_name` string\n- `level` int (optional) - defaults to 1\n- `depth` int (optional) - defaults to 0\n\n```twig\n{# Render a part of the admin menu #}\n{{ bamboo_render_menu('admin', 1, 2) }}\n```\n\n`bamboo_render_field(field_name, entity_type, id, langcode, formatter)` returns a render array of an entity field.\n\n- `field_name` string\n- `entity_type` string\n- `id` int (optional)\n- `langcode` string (optional) - defaults to current language\n- `formatter` string (optional) - The formatter that should be used to render the field\n\n```twig\n{# Render the title of node 1  #}\n{{ bamboo_render_field('title', 'node', 1) }}\n```\n\n`bamboo_render_region(region, theme_name)` returns a render array of the specified region.\n\n- `region` string\n- `theme_name` string (optional) - defaults to default theme\n\n```twig\n{# Render the sidebar_first region for current theme. #}\n{{ bamboo_render_region('sidebar_first') }}\n```\n\n**Image Styles**\n\n`bamboo_render_image(fid, style)` returns a render array of the specified image file.\n\n- `fid` int\n- `style` string\n- `alt` string (optional) - the image alternative text\n\n```twig\n{# Get thumbnail from image with fid 12. #}\n{{ bamboo_render_image(1, 'thumbnail', 'Alternative text.') }}\n```\n\n`bamboo_render_image_style(path, style, preprocess)` returns the URL string of the\nspecified image path or URI.\n\n- `path` string\n- `style` string\n- `preprocess` boolean - preprocess the image style before first HTTP call.\n\n```twig\n{# Get thumbnail from image `public://antistatique.jpg`. #}\n{{ bamboo_render_image_style('public://antistatique.jpg', 'thumbnail') }}\n```\n\n**Views**\n\n`bamboo_render_views(view, item)` renders the requested view.\n\n- `view` string\n- `item` string\n\n```twig\n{# Render the `who_s_new` View `block_1` block #}\n{{ bamboo_render_views('who_s_new', 'block_1') }}\n```\n\n**Configurations**\n\n`bamboo_config_get(config_key, name)` returns the specified config value.\n\n- `config_key` string\n- `name` string\n\n```twig\n{# Get system mail setting value #}\n{{ bamboo_config_get('system.site', 'mail') }}\n```\n\n`bamboo_state_get(state_key)` returns the specified state.\n\n- `state_key` string\n\n```twig\n{# Get system.cron_last from state #}\n{{ bamboo_state_get('system.cron_last') }}\n```\n\n`bamboo_settings_get(state_key)` returns the specified setting.\n\n- `state_key` string\n\n```twig\n{# Get hash_salt from settings #}\n{{ bamboo_settings_get('hash_salt') }}\n```\n\n**Security**\n\n`bamboo_has_role(role, user)` returns a boolean if the current|given user\nhas the requested role.\n\n- `role` string\n- `user` (optional) int - User id instead of the current logged user.\n\n```twig\n{# Does the current|given user have the given role ? #}\n{{ bamboo_has_role('authenticated') ? 'TRUE' : 'FALSE' }}\n```\n\nThe `bamboo_has_roles` function returns a boolean if the current|given user\nhas the requested roles.\n\n- `roles` string[]\n- `conjunction` (optional) string - The conjunction to use on the set of roles.\n  Only the two values 'AND' or 'OR' are allowed.\n- `user` (optional) int - User id instead of the current logged user.\n\n```twig\n{# Does the current user have all the given roles ? #}\n{{ bamboo_has_roles(['authenticated', 'administrator']) ? 'TRUE' : 'FALSE' }}\n{# Does the current user have at least one of the given roles ? #}\n{{ bamboo_has_roles(['authenticated', 'administrator'], 'OR') ? 'TRUE' : 'FALSE' }}\n```\n\n`bamboo_has_permission(permission, user)` returns TRUE if the current|given user\nhas the requested permission.\n\n- `permission` string\n- `user` (optional) int - User id instead of the current logged user.\n\n```twig\n{# Does the current|given user have the given permission ? #}\n{{ bamboo_has_permission('administer site configuration') ? 'TRUE' : 'FALSE' }}\n```\n\nThe `bamboo_has_permissions` function returns a boolean if the current|given user\nhas the requested permissions.\n\n- `permissions` string[]\n- `conjunction` (optional) string - The conjunction to use on the set of permissions.\n  Only the two values 'AND' or 'OR' are allowed.\n- `user` (optional) int - User id instead of the current logged user.\n\n```twig\n{# Does the current user have all the given permissions ? #}\n{{ bamboo_has_permissions(['administer site configuration', 'bypass node access']) ? 'TRUE' : 'FALSE' }}\n{# Does the current user have at least one of the given permissions ? #}\n{{ bamboo_has_permissions(['administer site configuration', 'bypass node access'], 'OR') ? 'TRUE' : 'FALSE' }}\n```\n\n**Cacheable**\n\n`bamboo_attach_cacheable_metadata(cacheable_metadata)` returns an array containing cacheable metadata.\n\n- `cacheable_metadata` array\n\n```twig\n{# Bubble the User Cache Context. #}\n{{ bamboo_attach_cacheable_metadata({'contexts': ['user']}) }}\n\n{# Bubble the Cache Tag. #}\n{{ bamboo_attach_cacheable_metadata({'tags': ['node:12']}) }}\n\n{# Bubble the Max-Age. #}\n{{ bamboo_attach_cacheable_metadata({'max-age': 12}) }}\n```\n\n**Extensions**\n\n`sentence|truncate(count, word, separator)` truncates a string.\nFrom Twig-extensions [Text](http://twig-extensions.readthedocs.io/en/latest/text.html).\n\n- `sentence` string\n- `count` int\n- `word` boolean - preserve whole words.\n- `separator` string - add characters to signify the ellipsis\n\n```twig\n{# Truncate a sentence #}\n{{ \"This is a very long sentence.\"|truncate(2, false, '...') }}\n```\n\n*coming soon* `sentence|bamboo_truncate_html(count, word, ellipsis)` truncates HTML sentences and preserves tags.\n\n- `sentence` string\n- `count` int\n- `word` boolean - preserve whole words.\n- `ellipsis` string\n\n```twig\n{# Truncate a HTML sentence #}\n{{ \"\u003cp\u003eThis \u003cb\u003eis a very\u003c/b\u003e long sentence.\u003c/p\u003e\"|bamboo_truncate_html(2, false, '...') }}\n```\n\n`array|shuffle` randomizes an array\nFrom Twig-extensions [Array](http://twig-extensions.readthedocs.io/en/latest/array.html).\n\n- `array` array\n\n```twig\n{# Shuffle the given array #}\n[1, 2, 3]|shuffle\n```\n\n`date|time_diff(date2)` returns a time difference between two dates.\nFrom Twig-extensions [Date](http://twig-extensions.readthedocs.io/en/latest/date.html).\n\n- `date` string - date, timestamp, DrupalDateTimePlus, DateTimePlus or DateTime\n- `date2` string - date, timestamp, DrupalDateTimePlus, DateTimePlus or DateTime\n\n```twig\n{# Difference between two dates #}\n{{ '24-07-2014 17:28:01'|time_diff('24-07-2014 17:28:06') }}\n```\n\n**Token**\n\n`bamboo_token(token)` substitutes a given tokens with its appropriate value.\n\n- `token` string\n\n```twig\n{# Substitute token #}\n{{ bamboo_token('site:name') }}\n```\n\n## Core Twig\n\nDrupal core already adds a [handful of custom functions](https://www.drupal.org/docs/8/theming/twig/functions-in-twig-templates) that are Drupal specific.\n\n**i18n**\n\n`string|trans` translates strings.\n\nSee the following [link](http://getlevelten.com/blog/mark-carver/drupal-8-twig-templates-and-translations) for more details.\n\n**Urls**\n\n`path(route, params, options)` returns an absolute URL from route name and parameters.\n\n- `route` string\n- `params` (optional) array\n- `options` (optional) array\n\n```twig\n{# Generates URL from route 'entity.user.canonical'. #}\n\u003ca href=\"{{ path('entity.user.canonical', {'user': user.id}) }}\"\u003eView user profile\u003c/a\u003e\n```\n\n`link(text, url, params)` returns `\u003ca\u003e` tag for the URL.\n\n- `text` string\n- `url` string\n- `params` (optional) array\n\n```twig\n{# Create a link with markup. #}\n{{ link('Homepage', item.url, { 'class':['foo', 'bar', 'baz']} ) }}\n```\n\n`file_url(uri)` returns a relative URL of a given URI or path to a file.\n\n- `uri` string - URI or string path to a file.\n\n```twig\n{# Generate a relative URI path to the file. #}\n{{ file_url('public://antistatique.jpg') }}\n```\n\n**Attachments**\n\n`attach_library(library)` attaches an asset library to the template,\nand hence to the response.\n\n- `library` string\n\n```twig\n{# Attaches an asset library to the template. #}\n{{ attach_library('classy/node') }}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fantistatique%2Fdrupal-bamboo-twig","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fantistatique%2Fdrupal-bamboo-twig","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fantistatique%2Fdrupal-bamboo-twig/lists"}