Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mbaynton/csv4twig
A CSV escaping filter for the Twig templating engine.
https://github.com/mbaynton/csv4twig
Last synced: 21 days ago
JSON representation
A CSV escaping filter for the Twig templating engine.
- Host: GitHub
- URL: https://github.com/mbaynton/csv4twig
- Owner: mbaynton
- Created: 2016-10-20T15:51:27.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2016-10-21T12:36:41.000Z (over 7 years ago)
- Last Synced: 2024-04-28T00:43:20.008Z (about 2 months ago)
- Language: PHP
- Size: 10.7 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Lists
- awesome-twig - csg4twig - A CSV escaping filter for the Twig templating engine. (Twig / Extensions)
- awesome-twig - csg4twig - A CSV escaping filter for the Twig templating engine. (Twig / Extensions)
README
# CSV4Twig
## CSV escaping filter for the Twig templating engine[![Build Status](https://travis-ci.org/mbaynton/csv4twig.svg?branch=master)](https://travis-ci.org/mbaynton/csv4twig)
CSV4Twig enables Twig templates to generate safe, properly-escaped
CSV output. It's useful when you need to get CSV reports out of an
existing application that has a Twig-enabled output layer.### Usage
1. Add it to your project with composer:
`composer require mbaynton/csv4twig:1.0.*`
2. Tell Twig about it. You'll need to get a hold of the
`\Twig_Environment` instance that will generate the CSV; then
just pass it to `\mbaynton\CSV4Twig\Filter::registerFilters()`.
3. Use it in your template with the autoescape tag:
```
{% autoescape "csv" %}
{{ some_value }},{{ another_value }}
{% endautoescape %}
```
The contents of `some_value` and `another_value` will be
escaped using the default CSV-escaping conventions
of PHP's `fputcsv()` function. `fputcsv()` is the function this
filter uses internally.
If you prefer, you can also escape certain values explicitly:
```
{% autoescape false %}
{{ some_value|e("csv") }},{{ another_value }}
{% endautoescape %}
```
That's it!