PHPackages                             kingkool68/sprig - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. kingkool68/sprig

ActiveWordpress-plugin[Templating &amp; Views](/categories/templating)

kingkool68/sprig
================

A minimal version of Twig for templating in WordPress

2.x-dev(4y ago)5154GPL-2.0-onlyPHPPHP &gt;=7.0.0

Since Jan 6Pushed 1y ago1 watchersCompare

[ Source](https://github.com/kingkool68/sprig)[ Packagist](https://packagist.org/packages/kingkool68/sprig)[ Docs](https://github.com/kingkool68/sprig)[ RSS](/packages/kingkool68-sprig/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (2)Versions (3)Used By (0)

Sprig
=====

[](#sprig)

*Bare bones Twig templating support for WordPress*

Sprig brings the Twig templating engine to WordPress. Install the plugin and get started separating your HTML from PHP.

Other Twig plugins like [Timber](https://www.upstatement.com/timber/) try to bring lots of WordPress functionality into Twig. Sprig believes in separating PHP from HTML as much as possible. PHP is for gathering and massaging data and Sprig/Twig templates are for rendering HTML using the data passed to it. Keep things simple and only pass data to a template that the template needs to render.

Installation
------------

[](#installation)

1. Clone this repo or download a zip
2. Add this to the plugin directory of your WordPress site in `/wp-content/plugins/`
3. Run `composer install` to download the [Twig](https://twig.symfony.com/) template engine dependency

How to Use
----------

[](#how-to-use)

Create a directroy in your theme called `views` or `twig` to hold your Twig template files. Render your templates using the following methods passing an array of data to be used by the template.

- `Sprig::render()` will render a Twig template using an array of data and return it as a string
- `Sprig::out()` will `echo` a rendered template
- `Sprig::do_action()` will capture the output of a WordPress action and return a string

Example
-------

[](#example)

**example.php**

```
