Git Product home page Git Product logo

ci-twig's Introduction

CI Twig โ€” Twig Templating For Codeigniter

The default Codeigniter view and parsing libraries leave a lot to be desired (mainly proper templating, better caching, better syntax..). Twig is a tried and tested templating library for PHP, so it makes sense to use it for your Codeigniter applications.

Installation

Copy all files from this repo into your Codeigniter application directory. Simple. It is recommended you add the library 'twig' to your config/autoload.php array so you don't have to keep loading it.

Does this support Modular Extensions HMVC?

Yes. Yes it does. Support for module view folders comes standard with CI Twig.

Does this work with Codeigniter 3.0?

Yes. This library is tried and tested with both the stable version of Codeigniter as well as the forever not complete Codeigniter 3.0.

How can I use Codeigniter helper functions in my templates?

In the config/twig.php file you will see two array values. One allows you to define functions for use in Twig templates and the other allows you to define custom filters.

The following example allows you to use base_url in your Twig templates, provided you have loaded the "url" helper somewhere in your app.

$config['twig.functions'] = array(
    "base_url"
);

How to use CI Twig in your projects

To use this library load it or better yet, autoload it. Then you can do stuff like this in your controllers.

// Loading the Ci Twig library manually
$this->load->library('twig');

$data['title'] = "Page Title";
$data['content'] = "<p>Welcome to my sexy page being displayed by Twig inside of Codeigniter</p>";

$this->twig->parse('yourtemplate.twig', $data);

Then in your templates to print out the value of the variable title, you would do the following:

{{ title }}

Ci Twig comes with an example controller and template for you to test it out of the box. Simply copy all files into your application/ directory and then visit your app in the browser and load the twigtest controller.

ci-twig's People

Contributors

vheissu avatar

Watchers

James Cloos avatar Alex Naupay 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.