apex/syrus

Light-weight, extensible template engine.

Installs: 669

Dependents: 2

Suggesters: 0

Security: 0

Stars: 3

Watchers: 2

Forks: 0

Open Issues: 0

Type:package

2.0.2 2022-04-13 04:31 UTC

This package is auto-updated.

Last update: 2022-11-13 05:53:14 UTC


README

A light weight, extensible template engine designed with separation of duties in mind, allowing both back-end developers and designers to complete their work independently. It supports:

  • Standardized <s:...) template tags providing short hand for larger HTML snippets, interopability across themes, plus additional PHP functionality.
  • Easily develop your own functional <s:...> template tags in addition to default set.
  • Easy loading of dynamic content such as breadcrumbs, social media links, and placeholders.
  • Multiple themes based on template file location (eg. different themes for public site, admin panel, and client area).
  • PSR6 caching, including configuration for no-cache pages and tags, and support for optional "cache" attribute within tags.
  • Optional auto-routing, automatically renders the appropriate template corresponding to the URI being viewed.
  • Optional per-template PHP class, which is automatically executed upon rendering the template providing bridge between templates and back-end application.
  • Developed with designers in mind, allowing them to work independently and without the need to navigate back-end software code.
  • Built-in support for Cluster, which makes an RPC call for every template rendered providing support for horizontal scaling including parameter based routing.
  • Optional built-in support for Apex Debugger to gather debugging information on templates rendered.

Installation

Install via Composer with:

composer require apex/syrus

Table of Contents

  1. Designers
    1. Getting Started
    2. File / Directory Structure
      1. Theme Structure
      2. Body Content Pages
      3. Public Assets
    3. Yield / Var Tags
    4. Variables, foreach, and if / else Tags
    5. <s:...> Template Tags
    6. Using Multiple Themes
  2. Developers
    1. Syrus class / Container Definitions
      1. site.yml Configuration File
    2. Render Templates
      1. Auto-Routing
      2. Executing Per Template PHP Files
      3. Utilizing RPC Calls
    3. Variables, Blocks and Callouts
    4. Content Loader (breadcrumbs, social media links, placeholders)
    5. Creating New <s...> Functional Tags
    6. StackElement Object
    7. Dummy Data for Designers
    8. Caching

Local Server

Get Syrus up and running with the default web site by running the following command within the ~/public/ directory:

php -S 127.0.0.1:8180

The default site including tag examples will now be available at http://127.0.0.1:8180/. Alternatively, if you have docker-compose installed you may achieve the same by running the following command:

sudo docker-compose up -d

Basic Usage

use Apex\Syrus\Syrus;

// Start
$syrus = new Syrus();

// Assign some variables
$syrus->assign('name', 'value');

// Assign array
$location = [
    'city' => 'Toronto', 
    'province' => 'Ontario', 
    'country' => 'Canada'
];
$syrus->assign('loc', $location);

// Add foreach blocks
$syrus->addBlock('users', ['username' => 'jsmith', 'email' => 'jsmith@domain.com']);
$syrus->addBlock('users', ['username' => 'mike', 'email' => 'mike@domain.com']);

// ADd error callout
$this->addCallout('Uh oh, there was a problem.', 'error');

// Render template
echo $syrus->render('contact.html');

// Or, use auto-routing and render template based on URI being viewed.
echo $syrus->render();

Support

If you have any questions, issues or feedback for Syrus, please feel free to drop a note on the ApexPl Reddit sub for a prompt and helpful response.

Follow Apex

Loads of good things coming in the near future including new quality open source packages, more advanced articles / tutorials that go over down to earth useful topics, et al. Stay informed by joining the mailing list on our web site, or follow along on Twitter at @mdizak1.