PHPackages                             html5/template - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. html5/template

ActiveLibrary[Templating &amp; Views](/categories/templating)

html5/template
==============

Inline Templating component

1.1.0(8y ago)13.1k1MITHTMLPHP &gt;=7.0

Since Jul 20Pushed 8y ago2 watchersCompare

[ Source](https://github.com/dermatthes/html-template)[ Packagist](https://packagist.org/packages/html5/template)[ Docs](http://leuffen.de)[ RSS](/packages/html5-template/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependencies (4)Versions (3)Used By (1)

[![Downloads this Month](https://camo.githubusercontent.com/ec6cf2fe947e96fa9831801fc82d80d6b991d51eb70df1429e2f3c0ad84a10d0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f68746d6c352f74656d706c6174652e737667)](https://packagist.org/packages/html5/template)[![](https://camo.githubusercontent.com/5a9dd9651efa7727f47673cc00ead81adc4e276b21e20456eac350d465a2c349/68747470733a2f2f7472617669732d63692e6f72672f6465726d6174746865732f68746d6c2d74656d706c6174652e737667)](https://travis-ci.org/dermatthes/html-template)[![Latest Stable Version](https://camo.githubusercontent.com/c8d285e4ea341b5647fe5c446836f4736580c0ba9b46a035c4c4e2e54218f5a9/68747470733a2f2f706f7365722e707567782e6f72672f68746d6c352f74656d706c6174652f762f737461626c65)](https://github.com/dermatthes/html-template/releases)

Html5 Template - Template Rendering
===================================

[](#html5-template---template-rendering)

angularjs-like inline-templates for PHP7.

> Planned as replacement for PHPTAL - which is quite fine but not enough extensible for cluster / platform usage.

Gismo Template does not precompile any code. It generates the pages on the fly.

Features:

- Works with HTML5 and XHTML (XHTML preferred)
- IDE supported template-development
- Generate HTML, plain-Text or struct-data from one file
- Supports macros
- Import other templates from virtual storage (cloud-ready)
- Verbose and useful error-messages with lineNo and xpath
- Secure and powerful expression engine (Symfony Component also used by Twig)

Example
-------

[](#example)

Template:

```
Welcome {{ user.name }}

```

Parser:

```
$template = new HtmlTemplate();
echo $template->render("template.xhtml", ["showHeader" => true, "producs"=> [ new Product("prod1"), new Product("Product2)" ]]);
```

Install using Composer
----------------------

[](#install-using-composer)

```
composer require html5/template

```

Attributes
----------

[](#attributes)

- `go-if`: Condition
- `go-foreach`: Loop
- `go-repeat`: Loop
- `go-continue`: Loop start-over
- `go-break`: Quit loop
- `go-bind`: Inject string data
- `go-html`: Inject html data

### Conditions

[](#conditions)

```

    Hello {{ name }}

```

### Foreach Loops

[](#foreach-loops)

```

    Product Title: {{product.title}}

```

```

    Key: {{curKey}} Value: {{curVal}}

```

### Repeat Loops

[](#repeat-loops)

```

    Line {{ myIndex }}: Hello

```

### break / continue a loop

[](#break--continue-a-loop)

You can use conditions to break or continue a loop

```

    ...

```

or use continue to skip elements:

```

    ...

```

### Bind escaped Value

[](#bind-escaped-value)

```
Name to show if user.name is null
```

The data will be escaped by `htmlspecialchars()`

### Bind Html-Code

[](#bind-html-code)

```
Show this if page.htmlCode is null
```

### Add CSS Classes dynamicly

[](#add-css-classes-dynamicly)

```
..
```

### Show/Hide Elements

[](#showhide-elements)

```

```

```

```

> if hidden it adds the css-class `ng-hide` (also used by angularjs)

Elements
--------

[](#elements)

- `go-text`: Inject Text
- `go-define`: Define Variables in Scope
- `go-dump`: Dump a variable or scope
- `go-macro`: Define a macro
- `go-callmacro`: Call a macro
- `go-struct`: Return array data sections defined by go-section
- `go-section`: Define or overwrite struct data

### Interceptors

[](#interceptors)

### Macros

[](#macros)

Macros can be used to create Output on multiple positions. To define a macro use the `go-macro`-Element:

```

                {{ curHeader }}

            ...

```

To generate your Table use `go-callmacro` - Element:

```

```

Benchmark
---------

[](#benchmark)

Small Example from above:

```
Parsing + Rendering:
