Composable template syntax for SilverStripe's template engine
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

SilverStripe Compose Parser

Allows the use of an html-like syntax for template includes, and new composition functionality for more reusable templates.

Installation (with composer)

composer require heyday/silverstripe-composeparser


A reusable button

<% if $href %>
    <a class="btn<% if $type %> btn-$type<% end_if %><% if $size %> btn-$size<% end_if %> $classes" href="$href"><% composed %></a>
<% else %>
    <button class="btn<% if $type %> btn-$type<% end_if %><% if $size %> btn-$size<% end_if %> $classes"><% composed %></button>
<% end_if %>

Using the button in a template

<:button type="default">A regular button</:button>

<:button type="default" href="">A link to heyday</:button>

The resulting html

<button class="btn btn-default">A regular button</button>

<a class="btn btn-default" href="">A link to heyday</a>

A reusable Nav

<ul class="nav <% if $classes %> $classes<% end_if %>"><% composed %></ul>

<li class="nav-item<% if $FirstLast %> nav-$FirstLast<% end_if %><% if $classes %> $classes<% end_if %>">
    <% if $Composed %>
        <% composed %>
    <% else %>
        <:navlink href=$href />
    <% end_if %>

<a href="$href" class="$LinkingMode"><% if $Composed %><% composed %><% else %>$MenuTitle<% end_if %></a>

Using the nav

Simple usage:
    <% loop $SomeSet %>
        <:navitem href=$Link />
    <% end_loop %>

Customised usage:
    <% loop $SomeSet %>
            <% if $SomeCondition %><span class="i-special-icon"></span><% end_if %>
            <navlink href=$Link/>
    <% end_loop %>