Skip to content

Rarst/meadow

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Meadow — WordPress Templating DSL

Write WordPress theme templates with familiar ease and modern features.

Scrutinizer Code Quality Version PHP required PDS Skeleton

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

Installation

Require package in your theme project with Composer:

composer require rarst/meadow

Instantiate object some time during theme load:

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

Templating

Meadow follows conventions of WordPress template hierarchy:

  • 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:

{{ the_title() }}

Filters

WordPress filters set up to be available as Twig filters:

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

Template Inheritance

Full range of Twig functionality is naturally available, including template inheritance:

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

{% block entry_title %}
	<div class="page-header">{{ parent() }}</div>
{% endblock %}

To inherit parent template in child theme prepend it with folder's name:

{# 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

{% 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):

License

MIT

About

WordPress templating DSL based on Twig.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published