Other Template Engines

Antlers is not always the best tool for the job. If you're using Statamic as a headless CMS or want to share views with a Laravel application, Blade or another engine might be a better fit.

Overview

While Statamic’s Antlers template language is powerful, tightly integrated, and simple to learn, it’s not the only way to build your frontend.

You can use Blade or other template engines by using their respective file extensions.

Instead of naming your views myview.antlers.html use .blade.php extension (or whatever other engine’s extensions you may have installed).

View Data

You will have access to the same top level data as you would in Antlers views.

---
title: My First Breakdance Competition
moves:
  - Toprock
  - 6-step
  - Windmill
  - L-kick
  - Headspin
---
I did not win but I did have good timez.
<h1>{{ $title }}</h1>

<p>First I did
@foreach ($moves as $move)
    {{ $move }}, then I did
@endforeach
and it was sick.</p>

{{ $content }}

Modifiers + Blade

You can use Modifiers in Blade templates with a Laravel-style fluent syntax.

Wrap your value with the Statamic\Modifiers\Modify::value() method and chain modifiers as you wish. The value will get passed along in sequence like it does in Antlers. Any parameters should be specified like regular PHP parameters.

{{ Statamic\Modifiers\Modify::value($content)->striptags()->backspace(1)->ensureRight('!!!') }}
THIS IS THE FIRST POST, HOW EXCITING!!!

You can use service injection to make your templates read a little nicer, and pass the value straight into it, rather than using a value method.

@inject('modify', 'Statamic\Modifiers\Modify')

{!! $modify($title)->wrap('h1') !!}
{{ $modify($content)->striptags()->backspace(1)->ensureRight('!!!') }}

Note that when using multi-word modifiers, like ensure_right, you should use the camelCased version (ensureRight).

Layouts

When Statamic attempts to render a URL (eg. an entry), two views are combined. A template gets injected into a layout’s template_content variable.

When the template is not an Antlers view, this rule doesn’t apply. The layout is ignored, allowing you to use @extends the way you would expect.

{{-- mytemplate.blade.php --}}

@extends('layout')

@section('body')
  The body content
@endsection
{{-- mylayout.blade.php --}}

<html>
<body>
  @yield('body')
</body>
</html>
<html>
<body>
  The body content
</body>
</html>

This rule only applies to the template. You’re free to use a .antlers.html template and a .blade.php layout. If you want to do this, instead of a yield, the contents of the template will be available as in the template_content variable.

{{# mytemplate.antlers.html #}}

The template content
{{-- mylayout.blade.php --}}

{!! $template_content !!}
<html>
<body>
The template contents
</body>
</html>
Betterify this page on Github!