Giter Club home page Giter Club logo

ci-jade-1's Introduction

ci-jade

ci-jade is a library for CodeIgniter to enable Jade Template Engine to render views with .jade extension.

  • all files in the view folder ending with .jade can be rendered from the controllers but you can still use any other files as views. So you're free to use Jade for all your views or just some of them.
  • use the 'cache' => true setting to render your views only once and save rendered files the cache folder, then serve cached file with no performance loss, views will be loaded as fast as the equivalent php views. You can also use 'cache' => '/your/cutom/path
  • ci-jade wait for you to load it. Only controllers with use Jade; will load the wrapper, and until you call $this->settings() or $this->view() in the controller, the template engine will not be loaded.

Installation

You need PHP 5.4 or later to run ci-jade. If you use a earlier version of PHP we recommand you to upgrade. If you cannot you can download the library version of ci-jade (available on PHP 5.3).

Open a terminal in the application folder in your CodeIgniter project, then enter:

composer require ci-jade/ci-jade

Be sure $config['composer_autoload'] = TRUE; in your application/config/config.php file

How to use it?

application/controllers/Main.php

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Main extends CI_Controller {

  use Jade;

  public function index()
  {
    $this->view('myview');
  }
}

application/views/myview.jade

doctype html
html(lang='en')
  head
    title My Jade View
  body
    h1 Hello World!

Pass variables

application/controllers/Main.php

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Main extends CI_Controller {

  use Jade;

  public function index()
  {
    $this->load->vars([
      'title' => 'My Jade View',
      'authors' => [
        'Luke',
        'Leia',
        'Lando'
      ]
    ]);
    $this->view('myview');
  }
}

or

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Main extends CI_Controller {

  use Jade;

  public function index()
  {
    $this->view('myview', [
      'title' => 'My Jade View',
      'authors' => [
        'Luke',
        'Leia',
        'Lando'
      ]
    ]);
  }
}

All variables from ->view() or ->load->vars() are merged and available in the view.

application/views/myview.jade

doctype html
html(lang='en')
  head
    title=title
  body
    ul
      each author in authors
        li=author

Keep rendered views in cache

We recommend you to do it in production to serve the views faster.

application/controllers/Main.php

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Main extends CI_Controller {

  use Jade;

  public function index()
  {
    $this->settings([
      'cache' => TRUE
    ]);
    $this->view('myview');
  }
}

Or you can use a custom storage folder:

$this->settings([
  'cache' => '/tmp/my-cache-folder'
]);

If the folder does not exists, the library will try to create it.

Custom views folder

If you do no store your .jade files in application/views, use the view_path setting:

$this->settings([
  'view_path' => APPPATH . 'jade-templates'
]);

ci-jade-1's People

Contributors

ci-jade avatar kylekatarnls avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.