Introduction

Manage custom view templates, assets, and data from your control panel.

Heads Up: The Templates module is a paid addon! Please checkout our store or ask about our developer partnership for repository access.

Features

The Templates module comes loaded with convenient features.

  • Manage custom Twig, HTML, and Markdown view templates.
  • Manage custom CSS, LESS, and SCSS assets.
  • Manage custom JSON and YAML data files.
  • All templates are routable.
  • Keep templates organized with templates groups.
  • Effortlessly sync, clean, and push templates to and from the database.
  • Integrates with Pyro's view and asset services.
  • Allows you to drop in files, sync, and have a website or project ready in minutes.

Installation

The Templates module is a paid addon and requires purchasing from the addon store OR a paid subscription.

Installing from Store Download

You can install the Templates module by downloading the addon and placing it within your site's addon directory:

/addons/{application_ref}/anomaly/*

Next install the addon with the addon:install command:

php artisan addon:install anomaly.module.templates
Installing with Composer Subscription

You can install the Templates module with Composer as a VCS repository if you have a subscription:

{
     "require": {
        "anomaly/templates-module": "~1.1.0"
    },
    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/anomalylabs/templates-module"
        }
    ]
}

Usage

This section will show you how to use the addon via API and in the view layer.

Groups

Groups represent file folders that help you organize your templates.

When creating and naming template groups keep in mind that the slug will be used as the directory name. The slug is also used when referring to the template:

view("templates::group_slug/template_name");

{{ asset_add("styles.css", "templates::group_slug/template_name.scss");

Templates

Templates represent physical files that are generated when saving a template. Templates can be used as a view, asset, or data.

The template slug will be used as the filename. The kind of template you create will dictate the extension following the filename.

For example if you create a Twig template with the slug example in the layouts template group the resulting file will be represented as:

/{templates_path}/layouts/example.twig

Using Templates as Views

Twig, HTML, and Markdown templates can all be used through the view system. To access them simply refer to them by their hinted path:

return view("templates::pages/hello");

You can also refer to templates directly from other templates and views:

{% extends "templates::layouts/example" %}

{% block content %}

    {% include "templates::partials/header" %}

    <p>Hello World!</p>
{% endblock %}

Using Templates as Assets

CSS, SCSS, LESS, JS, and Coffee templates can be used within the Asset class like any other asset. Simply reference it's hinted path to include it:

{{ asset_add("styles.css", "templates::stylesheets/theme.scss") }}

You can easily import other assets from within each other too:

@import "header.scss"; // Reference another file within the same template group.
@import "../mixins/theme.scss"; // Assuming you have a template group named "Mixins"

Using Templates as Data

Sometimes you might want to store data within a template and parse it later. You can use the template plugin function to get the templates content and parse it:

{% set data = yaml(template("example/test_data.yaml").content()) %}

The same can be done via API:

$template = app(TemplateRepositoryInterface::class)->findByPath('example/test_data.yaml');

$yaml = (new Yaml)->parse($template->content);

Artisan

This section will go over how to use the Templates module with Laravel's Artisan console.

templates:sync

The sync command will loop over all template files and syncs them to the database.

php artisan templates:sync

templates:clean

The clean method will go through all template files and removes any not found in the database.

php artisan templates:clean

templates:push

The push command will push all templates from the database to the filesystem. This is useful if you import templates via an SQL import.

php artisan templates:push