2017 © Pedro Peláez
 

library template-manager

Template manager for laravel

image

corb/template-manager

Template manager for laravel

  • Thursday, March 24, 2016
  • by corb
  • Repository
  • 1 Watchers
  • 0 Stars
  • 13 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 8 % Grown

The README.md

CORB TEMPLATE MANAGER

A database template compiler for laravel 5, (*1)

Installation

  • Install as laravel project dependency, (*2)

    composer require corb/template-manager, (*3)

  • Add service provider in providers array (config/app.php), (*4)

    Corb\TemplateManager\TemplateManagerServiceProvider::class,, (*5)

  • Publish vendor files, (*6)

    $ php artisan vendor:publish --tag=config, (*7)

This will create a config file named template-manager.php, (*8)

Configuration file

  • models, (*9)

    The model property is an array containing Model Namespaces to access table columns., (*10)

    'models' => [ App\User::class ];, (*11)

    or, (*12)

    models => [ 'App\User' ];, (*13)

    Why? If you want to implement a WYSIWYG edit maybe this option is useful., (*14)

  • use_routes, (*15)

    If you want to use package routes to get available table fields set to true (default)., (*16)

    'use_routes' => true,, (*17)

  • route Url of the route, default 'templates', (*18)

    'route' => 'templates',, (*19)

    Ex: localhost:8000/templates' //This url return all the configured tables with its columns, (*20)

  • template_table, (*21)

    Name of the database table to be used, default 'templates'., (*22)

    'template_table' => 'templates',, (*23)

    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)., (*24)

Template table

  • Create migration, (*25)

    $ php artisan vendor:publish --tag=migrations, (*26)

    This command create a new database migration using configuration file. Remember previous warning!., (*27)

  • Run migrate, (*28)

    $ php artisan migrate, (*29)

    And thats it, now store your templates., (*30)

Usage

Compiling a template

Add the TemplateManager class to your code, (*31)

use Corb\TemplateManager\TemplateManager;, (*32)

Create a new TemplateManager object, (*33)

$template = new TemplateManager;, (*34)

Compile a new template, (*35)

$compiled_template = $template->parse('test_template', $template_data), (*36)

Example

Database template: test_template
Hi <b>{{$user->name}}</b>.<br/>
Thanks to use corb template manager, if you need help 
<a href="{{$help_link}}">Click here</a>.
Test code: routes.php
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);
});
Result
Hi Foo.
Thanks to use corb template manager, if you need help Click here.

TemplateManager Methods

getModels()
  • Get models found in config file
  • Return array, (*37)

    [
        "App\User",
        "App\Product",
    ]
getFields()
  • Get table columns from config models
  • Return array, (*38)

    [
        "users": [
            "id",
            "name",
            "email",
        ],
        "products": [
            "id",
            "name",
            "category",
            "sku"
        ]
    ]
parse($slug, $data)
  • Parse a template
  • Params:, (*39)

    - $slug: template slug
    - $data: Array of data to be parsed in template

    -Return: A string of compiled template, (*40)

The Versions

24/03 2016

dev-master

9999999-dev https://github.com/gabomarin/l5-template-manager.git

Template manager for laravel

  Sources   Download

The Requires

  • php >=5.5.9

 

laravel template

24/03 2016

dev-dev

dev-dev https://github.com/gabomarin/l5-template-manager.git

Template manager for laravel

  Sources   Download

The Requires

  • php >=5.5.9

 

laravel template

24/03 2016

v0.1

0.1.0.0 https://github.com/gabomarin/l5-template-manager.git

Template manager for laravel

  Sources   Download

The Requires

  • php >=5.5.9

 

laravel template