Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wearewondrous/fractal-twig-drupal-adapter
Twig template adapter for Fractal with Drupal 8 directives.
https://github.com/wearewondrous/fractal-twig-drupal-adapter
drupal drupal-8 fractal twig
Last synced: 2 months ago
JSON representation
Twig template adapter for Fractal with Drupal 8 directives.
- Host: GitHub
- URL: https://github.com/wearewondrous/fractal-twig-drupal-adapter
- Owner: wearewondrous
- License: mit
- Archived: true
- Created: 2017-08-29T13:05:31.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2020-05-13T19:38:40.000Z (over 4 years ago)
- Last Synced: 2024-09-25T18:08:58.445Z (3 months ago)
- Topics: drupal, drupal-8, fractal, twig
- Language: JavaScript
- Homepage: http://fractal.build
- Size: 25.4 KB
- Stars: 13
- Watchers: 8
- Forks: 13
- Open Issues: 22
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- component-based-theming - Twig adapter with Drupal-specific support
README
# Twig Adapter
An adapter to let you use [Twig](https://github.com/twigjs/twig.js) templates with [Fractal](http://github.com/frctl/fractal).
## Installation
```bash
$ npm install --save @wearewondrous/fractal-twig-drupal-adapter
```in your `fractal.js`
```js
const fractal = require('@frctl/fractal').create();
const twigAdapter = require('@wearewondrous/fractal-twig-drupal-adapter');
const twig = twigAdapter({
handlePrefix: '@components/',
});fractal.components.engine(twig);
fractal.components.set('ext', '.twig');
```## Usage
This adapter allows you to use some Drupal filters, functions and tags.
### Supported Filters
`|t` - The Drupal core translation filter. Additional parameters not supported, yet.
`|field_value` - Provided by the module [drupal/twig_field_value](https://www.drupal.org/projects/twig_field_value) to use plain outputs from a field.
#### Add Custom Filters
You have the ability to extend Twig with custom filters by adding any filter functions to the twigAdapter configuration. The name of the function will be used as the filter name. For example, to create a `|render` filter:
```js
const twig = twigAdapter({
filters: {
render(str) {
return str;
}
}
});
```### Supported Functions
`path()` - The Drupal core path function.
`url()` - The Drupal core url function.
`block_view()` - Provided by the module [drupal/twig_extender](https://www.drupal.org/projects/twig_extender) to directly print a block.
### Supported tags
`{% trans %}` - The Drupal core translate tag.
## Creator
[WONDROUS](https://www.wearewondrous.com/)
[MIT License](LICENSE)