Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/krowinski/laravel-xslt

XSLT template engine for laravel
https://github.com/krowinski/laravel-xslt

composer-packages laravel laravel-xslt php xml xslt-template-engine

Last synced: 16 days ago
JSON representation

XSLT template engine for laravel

Awesome Lists containing this project

README

        

# laravel-xslt

[![Latest Stable Version](https://poser.pugx.org/krowinski/laravel-xslt/v/stable)](https://packagist.org/packages/krowinski/laravel-xslt) [![Total Downloads](https://poser.pugx.org/krowinski/laravel-xslt/downloads)](https://packagist.org/packages/krowinski/laravel-xslt) [![Latest Unstable Version](https://poser.pugx.org/krowinski/laravel-xslt/v/unstable)](https://packagist.org/packages/krowinski/laravel-xslt) [![License](https://poser.pugx.org/krowinski/laravel-xslt/license)](https://packagist.org/packages/krowinski/laravel-xslt)

XSLT template engine for laravel

# Instalation

1. Install using composer in your laravel project

```sh
composer require krowinski/laravel-xslt
```

2. Add this line to app.php at the end of 'providers' array (in file config/app.php)

```php
Krowinski\LaravelXSLT\XSLTServiceProvider::class,
```

3. Create welcome.xsl in resources/views

```html


Laravel


html, body {
height: 100%;
}

body {
margin: 0;
padding: 0;
width: 100%;
display: table;
font-weight: 100;
font-family: 'Lato';
}

.container {
text-align: center;
display: table-cell;
vertical-align: middle;
}

.content {
text-align: center;
display: inline-block;
}

.title {
font-size: 96px;
}





Laravel 5 XSLT engine template




```

4. Add data to xml using simple xml functions

```php
/**
* Show the application welcome screen to the user.
*
* @return Response
*/
public function index()
{
// adds to main xml /App attributte name template with value = hello
\View::addAttribute('name_template ', 'hello');
// create child template to /App with value hello and add aaa and zzz atribute to template.
\View::addChild('template', 'hello', false)->addAttribute('aaaa', 'zzz');
// creates parent example and adds childs foo and bar to it
\View::addArrayToXmlByChild(['foo', 'bar'], 'example', false);
// add to parent App child bar and zzz
\View::addArrayToXml(['bar', 'zzz'], false);

return view('welcome');
}
```

# Add xml to debugBar (https://github.com/barryvdh/laravel-debugbar)

Add to EventServiceProvider.php

```php
use Krowinski\LaravelXSLT\Engines\XSLTEngine;
```

and to protected $listen array

```php
XSLTEngine::EVENT_NAME => [
'App\Listeners\XSLTDebugBar'
],
```

create file Listeners\XSLTDebugBar.php
```bash
php artisan make:listener XSLTDebugBar --event XSLTEngineEvent
```

event content

```php
preserveWhiteSpace = false;
$dom->loadXML($event->getExtendedSimpleXMLElement()->saveXML());
$dom->formatOutput = true;
$xmlString = $dom->saveXML();

/** @var DebugBar $debugBar */
$debugBar = App::make('debugbar');
if (!$debugBar->hasCollector('XML')) {
$debugBar->addCollector(new MessagesCollector('XML'));
}
/** @var MessagesCollector $collector */
$collector = $debugBar->getCollector('XML');
$collector->addMessage($xmlString, 'info', false);
}
}
```