vmoulin78 / codeigniter-layout-library

CodeIgniter Template Library
MIT License
24 stars 9 forks source link
codeigniter-layout-library codeigniter-template-library

CodeIgniter Layout Library

Installation

  1. Copy the file ./application/libraries/Layout.php
  2. Copy the file ./application/config/config_layout.php
  3. Open the file ./application/config/autoload.php:
    • add 'layout' to the array $autoload['libraries']
    • add 'url' to the array $autoload['helper'] if not already added
    • add 'config_layout' to the array $autoload['config']
  4. Create the structure ("Welcome" and "hello" is for example):

    ├── application
    │   ├── templates
    │   └── views
    │       └── controllers
    │           └── Welcome
    │               └── actions
    │                   └── hello.php
    │
    └── web
        ├── css
        │   ├── controllers
        │   │   └── Welcome
        │   │       ├── actions
        │   │       │   └── hello.css
        │   │       │
        │   │       └── controller.css
        │   │
        │   └── app.css
        │
        └── js
            ├── controllers
            │   └── Welcome
            │       ├── actions
            │       │   └── hello.js
            │       │
            │       └── controller.js
            │
            └── app.js

    Note: Create the css and javascript files only if needed !

Description

The getters

The setters

The "breadcrumb" section

The "asset" section

Note: The basic assets are defined in the variables $config['layout_basic_css'] and $config['layout_basic_js'] of the configuration file config_layout.php.

Note: If a basic asset is a string, it is considered as a local uri asset with no attributes and no tags.

Note: Tags are useful if you want to put some javascript at one place (for example in the head section) and some other javascript at another place (for example in the bottom of the page).
All tags must be declared in the variables $config['layout_css_tags'] and $config['layout_js_tags'] of the configuration file config_layout.php.

Example:

$config['layout_basic_css'] = array(
    'css/app.css',
    array(
        'type'        => 'uri',
        'uri'         => 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css',
        'location'    => 'remote',
        'attributes'  => array(
            'integrity'    => 'sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u',
            'crossorigin'  => 'anonymous',
        ),
    ),
);
$config['layout_basic_js'] = array(
    'js/app.js',
    array(
        'type'        => 'uri',
        'uri'         => 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js',
        'location'    => 'remote',
        'attributes'  => array(
            'integrity'    => 'sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa',
            'crossorigin'  => 'anonymous',
            'async'        => true,
            'defer'        => false,
        ),
    ),
    array(
        'type'     => 'str',
        'content'  => '/* some javascript code */',
        'tags'     => ['page_head'],
    ),
    array(
        'type'      => 'php',
        'callback'  => 'my_function',
        'tags'      => ['page_bottom'],
    ),
    array(
        'type'      => 'php',
        'callback'  => ['My_class', 'my_method'],
    ),
);
$config['layout_css_tags']  = [];
$config['layout_js_tags']   = ['page_head', 'page_bottom'];

The triggers

The triggers have to be used in the templates.

The "template" section

Note:

The "view" section