Package Data | |
---|---|
Maintainer Username: | corb |
Maintainer Contact: | gabriel.ortiz@corb.mx (Gabriel Ortiz) |
Package Create Date: | 2016-03-18 |
Package Last Update: | 2016-06-30 |
Language: | PHP |
License: | Unknown |
Last Refreshed: | 2025-01-15 03:01:57 |
Package Statistics | |
---|---|
Total Downloads: | 70 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 0 |
Total Watchers: | 2 |
Total Forks: | 0 |
Total Open Issues: | 0 |
A database template compiler for laravel 5
Install as laravel project dependency
composer require corb/template-manager
Add service provider in providers array (config/app.php)
Corb\TemplateManager\TemplateManagerServiceProvider::class,
Publish vendor files
$ php artisan vendor:publish --tag=config
This will create a config file named template-manager.php
models
The model property is an array containing Model Namespaces to access table columns.
`'models' => [
App\User::class
];
`
or
`models => [
'App\User'
];
`
Why? If you want to implement a WYSIWYG edit maybe this option is useful.
use_routes
If you want to use package routes to get available table fields set to true (default).
'use_routes' => true,
route Url of the route, default 'templates'
'route' => 'templates',
Ex:
localhost:8000/templates'
//This url return all the configured tables with its columns
template_table
Name of the database table to be used, default 'templates'.
'template_table' => 'templates',
WARNING: This configuration is used to create database migration. If you have an older migration it will be useless, so maybe you want to delete the migrate (Need to improve this).
Create migration
$ php artisan vendor:publish --tag=migrations
This command create a new database migration using configuration file. Remember previous warning!.
Run migrate
$ php artisan migrate
And thats it, now store your templates.
Add the TemplateManager class to your code
use Corb\TemplateManager\TemplateManager;
Create a new TemplateManager object
$template = new TemplateManager;
Compile a new template
$compiled_template = $template->parse('test_template', $template_data)
##Example
Hi <b>{{$user->name}}</b>.<br/>
Thanks to use corb template manager, if you need help
<a href="{{$help_link}}">Click here</a>.
use Corb\TemplateManager\TemplateManager;
Route::get('/', function () {
$template = new TemplateManager;
$user = new stdClass;
$user->name = 'Foo';
$help_link = 'https://github.com/gabomarin/l5-template-manager';
$data = [
'user' => $user,
'help_link' => $date
];
echo $template->parse('test_template', $data);
});
Hi Foo.
Thanks to use corb template manager, if you need help Click here.
Get models found in config file
Return array
[ "App\User", "App\Product", ]
Get table columns from config models
Return array
[ "users": [ "id", "name", "email", ], "products": [ "id", "name", "category", "sku" ] ]
Parse a template
Params: