Coder Social home page Coder Social logo

helpfulrobot / heyday-silverstripe-composeparser Goto Github PK

View Code? Open in Web Editor NEW

This project forked from wpp-public/akqa-nz-silverstripe-composeparser

0.0 2.0 0.0 72 KB

Composable template syntax for SilverStripe's template engine

License: MIT License

PHP 100.00%

heyday-silverstripe-composeparser's Introduction

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

Examples

A reusable button

button.ss

<% 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="http://heyday.co.nz">A link to heyday</:button>

The resulting html

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

<a class="btn btn-default" href="http://heyday.co.nz/">A link to heyday</a>

A reusable Nav

nav.ss

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

navitem.ss

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

navlink.ss

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

Using the nav

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

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

heyday-silverstripe-composeparser's People

Contributors

camspiers avatar

Watchers

James Cloos avatar helpfulrobot avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.