2017 © Pedro Peláez
 

library meadow

WordPress templating DSL

image

rarst/meadow

WordPress templating DSL

  • Monday, January 29, 2018
  • by Rarst
  • Repository
  • 8 Watchers
  • 65 Stars
  • 117 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 3 Forks
  • 2 Open issues
  • 3 Versions
  • 1 % Grown

The README.md

Meadow — WordPress Templating DSL

Write WordPress theme templates with familiar ease and modern features., (*1)

Scrutinizer Code Quality Version PHP required PDS Skeleton, (*2)

Meadow is a theme templating solution, aiming to find a balance between native WordPress concepts and power of Twig dedicated templating language., (*3)

Installation

Require package in your theme project with Composer:, (*4)

composer require rarst/meadow

Instantiate object some time during theme load:, (*5)

$meadow = new \Rarst\Meadow\Core;
$meadow->enable();

Templating

Meadow follows conventions of WordPress template hierarchy:, (*6)

  • 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:, (*7)

{{ the_title() }}

Filters

WordPress filters set up to be available as Twig filters:, (*8)

{{ 'This is the title'|the_title }}

Template Inheritance

Full range of Twig functionality is naturally available, including template inheritance:, (*9)

{# single.twig #}
{% extends 'index.twig' %}

{% block entry_title %}





{% endblock %}

To inherit parent template in child theme prepend it with folder's name:, (*10)

{# 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., (*11)

This is primarily achieved by implementing custom Twig tags, abstracting away complexities for specific tasks., (*12)

Loop

{% loop %}
    <h2><a href="{{ the_permalink() }}">{{ the_title() }}</a></h2>
    {{ the_content() }}
{% endloop %}

Secondary Loop

{% loop { 'post_type' : 'book', 'orderby' : 'title' } %} {# expression for arguments #}
    <h2><a href="{{ the_permalink() }}">{{ the_title() }}</a></h2>
    {{ the_content() }}
{% endloop %}

Comments

<ul class="comment-list">
    {% comments %}
    <li>
        {{ comment_text() }}
    {# no </li> - self-closing #}
    {% endcomments %}
</ul>

Template Examples

In Hybrid Wing theme (work in progress):, (*13)

License

MIT, (*14)

The Versions

29/01 2018

dev-master

9999999-dev https://github.com/Rarst/meadow

WordPress templating DSL

  Sources   Download

MIT

The Requires

 

The Development Requires

wordpress twig

10/12 2016

0.2

0.2.0.0 https://github.com/Rarst/meadow

WordPress templating DSL

  Sources   Download

MIT

The Requires

 

wordpress twig

13/04 2015

0.1

0.1.0.0 https://github.com/Rarst/meadow

WordPress templating DSL

  Sources   Download

MIT

The Requires

 

wordpress twig