Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/krowinski/laravel-xslt
- Owner: krowinski
- Created: 2015-04-08T15:33:38.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2019-12-20T14:07:56.000Z (almost 5 years ago)
- Last Synced: 2024-07-27T16:24:12.847Z (4 months ago)
- Topics: composer-packages, laravel, laravel-xslt, php, xml, xslt-template-engine
- Language: PHP
- Homepage:
- Size: 45.9 KB
- Stars: 14
- Watchers: 3
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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);
}
}
```