Reusable Templates for SilverStripe
Scheme PHP
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

SilverStripe Reusable Html

All of Bootstrap's boilerplate element structures as composable templates, as well as some other common HTML structures. Composable templates are achieved using heyday/silverstripe-composeparser, which also provides the short include syntax used in this readme (eg. <:MyTemplate/>).

Installation (with composer)

$ composer require heyday/silverstripe-reusablehtml

Usage example

A Bootstrap modal:

<:bsmodal fade=1>
        <h2>Hello, world!</h2>

        <p>We're in a Bootstrap modal!</p>

For a full list of templates provided by this module, look in the templates directory.

Template blocks

Reusable HTML adds two additional template blocks that are used in the templates it provides: required and dataattrs. These can also be used in your own templates.

<% required %>

The required block allows defining a list of variables that must be present for the template to render. Missing variables will cause an exception to be thrown during template rendering.

<:MyTemplate foo="Hello"/>

<% required $foo, $bar %>

// Result
InvalidArgumentException: the field 'bar' is required

<% dataattrs %>

The data attributes block renders all HTML data attributes passed into an include statement. No closing block is required.

<:MyTemplate data-foo="bar"/>

<div <% dataattrs %>></div>

// Rendered
<div data-foo="bar"></div>