Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rarst/meadow
WordPress templating DSL based on Twig.
https://github.com/rarst/meadow
twig wordpress
Last synced: 2 months ago
JSON representation
WordPress templating DSL based on Twig.
- Host: GitHub
- URL: https://github.com/rarst/meadow
- Owner: Rarst
- License: mit
- Created: 2014-03-21T21:37:14.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2018-12-31T08:33:54.000Z (almost 6 years ago)
- Last Synced: 2024-10-17T08:50:38.106Z (2 months ago)
- Topics: twig, wordpress
- Language: PHP
- Homepage:
- Size: 35.2 KB
- Stars: 72
- Watchers: 9
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Meadow — WordPress Templating DSL
_Write WordPress theme templates with familiar ease and modern features._
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/Rarst/meadow/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/Rarst/meadow/?branch=master)
[![Version](https://img.shields.io/packagist/v/rarst/meadow.svg?label=version)](https://packagist.org/packages/rarst/meadow)
[![PHP required](https://img.shields.io/packagist/php-v/rarst/meadow.svg)](https://packagist.org/packages/rarst/meadow)
[![PDS Skeleton](https://img.shields.io/badge/pds-skeleton-blue.svg?style=flat-square)](https://github.com/php-pds/skeleton)Meadow is a theme templating solution, aiming to find a balance between native WordPress concepts and power of [Twig](http://twig.sensiolabs.org/) dedicated templating language.
## Installation
Require package in your theme project with [Composer](https://getcomposer.org/):
```bash
composer require rarst/meadow
```Instantiate object some time during theme load:
```php
$meadow = new \Rarst\Meadow\Core;
$meadow->enable();
```## Templating
Meadow follows conventions of WordPress [template hierarchy](https://codex.wordpress.org/Template_Hierarchy#Visual_Overview):
- for example `index.php` becomes `index.twig`.
- `{{ get_header() }}` will look for `header.twig` (with fallback to `header.php`)
- and so on.### Template Tags
Template Tags API (and PHP functions in general) are set up to work transparently from Twig templates:
```twig
{{ the_title() }}
```### Filters
WordPress filters set up to be available as Twig filters:
```twig
{{ 'This is the title'|the_title }}
```### Template Inheritance
Full range of Twig functionality is naturally available, including [template inheritance](http://twig.sensiolabs.org/doc/templates.html#template-inheritance):
```twig
{# single.twig #}
{% extends 'index.twig' %}{% block entry_title %}
{{ parent() }}
{% endblock %}
```To inherit parent template in child theme prepend it with folder's name:
```twig
{# child-theme/index.twig #}
{% extends 'parent-theme/index.twig' %}
```## Domain Specific Language
Meadow attempts not just "map" WordPress to Twig, but also meaningfully extend both to improve historically clunky WP constructs.
This is primarily achieved by implementing custom Twig tags, abstracting away complexities for specific tasks.
### Loop
```twig
{% loop %}
{{ the_title() }}
{{ the_content() }}
{% endloop %}
```### Secondary Loop
```twig
{% loop { 'post_type' : 'book', 'orderby' : 'title' } %} {# expression for arguments #}
{{ the_title() }}
{{ the_content() }}
{% endloop %}
```### Comments
```twig
```
## Template Examples
In [Hybrid Wing](https://github.com/Rarst/hybrid-wing) theme (work in progress):
- [`index.twig`](https://github.com/Rarst/hybrid-wing/blob/master/index.twig)
- [`single.twig`](https://github.com/Rarst/hybrid-wing/blob/master/single.twig)
- [`single-post.twig`](https://github.com/Rarst/hybrid-wing/blob/master/single-post.twig)
- [`comments.twig`](https://github.com/Rarst/hybrid-wing/blob/master/comments.twig)
## License
MIT
{% comments %}
{{ comment_text() }}
{# no
{% endcomments %}