# eleventy-plugin-twig-php

> Twig PHP template engine for Eleventy

Latest version **0.3.0** (published 2022-09-13) · LGPL-3.0-or-later license · 0 weekly downloads

## Install

```sh
npm install eleventy-plugin-twig-php
pnpm add eleventy-plugin-twig-php
yarn add eleventy-plugin-twig-php
bun add eleventy-plugin-twig-php
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; large bundle; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.0 |
| Published | 2022-09-13 |
| First published | 2022-06-17 |
| Weekly downloads | 0 |
| License | LGPL-3.0-or-later |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 38.6 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | René Stalder |
| Maintainers | renestalder |
| Keywords | twig, eleventy, 11ty, 11ty-plugin, eleventy-plugin |

## Links

- npm: https://www.npmjs.com/package/eleventy-plugin-twig-php
- Repository: https://gitlab.com/renestalder/eleventy-plugin-twig-php
- Homepage: https://gitlab.com/renestalder/eleventy-plugin-twig-php#readme
- Issues: https://gitlab.com/renestalder/eleventy-plugin-twig-php/-/issues
- npm.io page: https://npm.io/package/eleventy-plugin-twig-php

## Dependencies (1)

- [@basalt/twig-renderer](https://npm.io/package/@basalt/twig-renderer.md) ^2.1.0

## Alternatives

- [async-exit-hook](https://npm.io/package/async-exit-hook.md) — 3.7M weekly downloads
- [evnty](https://npm.io/package/evnty.md) — 7.2K weekly downloads
- [eleventy-plugin-asciidoc](https://npm.io/package/eleventy-plugin-asciidoc.md) — 3.5K weekly downloads
- [@jswork/next-get2get](https://npm.io/package/@jswork/next-get2get.md) — 945 weekly downloads
- [@dashersw/axon](https://npm.io/package/@dashersw/axon.md) — 934 weekly downloads

## Recent versions

- 0.3.0 (latest) — 2022-09-13
- 0.2.0 — 2022-07-29
- 0.1.2 — 2022-06-17
- 0.1.1 — 2022-06-17

## README

# 11ty (Eleventy) Twig PHP Plugin

> Under development

Plugin to add support for rendering Twig templates in Eleventy with the
original PHP Twig engine. Supports all features of the official Twig
specification, [version 2.x](https://twig.symfony.com/doc/2.x/).
**Requires PHP to be installed in the build environment**.

## Use cases

- You want build websites with 11ty and want to use the full feature set
  of Twig according to the supported version of this plugin.
- You want to use 11ty for building component libraries and
  documentations that are consumed by PHP projects (therefore need
  feature parity).
- You want to compile Twig outside of PHP projects.

## Alternatives

- **[Eleventy Plugin Twig](https://github.com/factorial-io/eleventy-plugin-twig)**:
  11ty Twig plugin using TwigJS under the hood. TwigJS doesn't have full
  feature parity with the original PHP engine. But the this plugin comes
  with handy additions on top for building websites, like image
  resizing, and might be a better, more lightweight approach to using
  Twig with 11ty if you have an environment without PHP support. Or
  simply want an out-of-the-box toolset for building websites with Twig.

## Getting started

### Requirements

- **PHP and composer needs to be available in your build environment**.
  This also means, these projects can only build in CI/CD environments
  that have PHP installed.

### Installation

Install the plugin via your preferred Node package manager.

_Example for npm:_

```
npm install --save-dev eleventy-plugin-twig-php
```

### Usage

Add the plugin to your Eleventy configuration, e.g. `.eleventy.js`:

```js
const twig = require('eleventy-plugin-twig-php');

module.exports = function (eleventyConfig) {
  eleventyConfig.addPlugin(twig, options);

  // Other configuration...
};
```

#### Options

##### `twig.namespaces`

Set up Twig namespaces. Example:

```js
const twig = require('eleventy-plugin-twig-php');

module.exports = function (eleventyConfig) {
  eleventyConfig.addPlugin(twig, {
    twig: {
      namespaces: {
        macros: 'path/to/macro/folder',
      },
    },
  });

  // Other configuration...
};
```

```twig
{# Imports path/to/macro/folder/my-macro.twig #}
{% from '@macros/my-macro' import my_macro %}
```

## Development

```sh
npm ci
npm run test
```

### Docker

The project comes with a `docker-compose.yml`. To make usage easier, it
also includes a `Makefile` to run node commands directly in the Docker
container:

```sh
make install
make test
```

## Acknowledgements

- The fantastic work of knapsack-cloud/basalt on the
  [PHP Twig renderer for node](https://github.com/knapsack-cloud/twig-renderer)
- [patternlab](https://patternlab.io/) for being a great toolset for
  years, that has shown me how the PHP version of Twig can be cleverly
  used together with Node.

## Contributing

See `CONTRIBUTING.md` for a few guidelines.

---
_Source: https://npm.io/package/eleventy-plugin-twig-php · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
