Installation #

Twilight allows you to build PHP/WordPress sites in a component-based way. Twilight requires PHP version 8.2 or higher. To get started, install it with Composer:

composer require chrismademe/twilight

What Is It? #

If you're familiar with building templates in Twig, or even WordPress - you'll know that one of the big things that it doesn't really allow for it components. In Twig, you might do something like this:


{% set content %}
  <h1>WordPress Website Development</h1>
  <p>Expert WordPress Development services in London</p>
{% endset %}

{% include "partials/hero.twig" with { image: '/images/hero.jpg', content: content } %}

This is fine, but it doesn't "feel" like HTML. And what if you want to manipulate or do something with that incoming data on the component side?

Twilight adds a Component syntax to Twig, so you can do this:

<Hero image="/images/hero.jpg">
  <h1>WordPress Website Development</h1>
  <p>Expert WordPress Development services in London</p>
</Hero>

How about switching an HTML element or attribute based on a condition, well here's what it can look like in Twig:

{% set Tag = href ? 'a' : 'button' %}

<{{ Tag }} {{ href ? 'href="' ~ href ~ '"' : '' }}>
  Button
</{{ Tag }}>

It can get pretty narly. In Twilight, you can do this:

<Element :is="href ? 'a' : 'button'" :href="href">
  Button
</Element>

But that's not all, have a read through the docs to learn about passing data to components, manipulating that data and the handy directives that you can use in your templates.