CodeIgniter 模板引擎:Stencil

jopen 10年前

Stencil 是一个PHP框架 CodeIgniter 的模板引擎,用于以简单、可靠、强大的方式来生成 HTML 页面。

特性:

Layouts
Codeigniter 2.1.3 Ready
Slices

Child Views Partials Nested Views Elements Includes

HTML5 Helpers

add_css() add_js() add_meta() shiv() chrome_frame() view_port() apple_mobile() windows_tile() favicons() jquery() asset_url()

Load Page Specific Assets

JS CSS Perfect for jQuery Plugins

Slice Callbacks

Run or return a block of code everytime a view is called

Asset Management
Smart Data Binding to Views

$this->stencil->data('key', 'value') $this->stencil->data(array('key' => 'value'))

控制器:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');    class Home extends CI_Controller {        public function __construct()      {          parent::__construct();          $this->stencil->layout('home_layout');          $this->stencil->slice('header');          $this->stencil->slice('footer');      }        public function index()      {          $this->stencil->title('Home Page');            $this->stencil->js('some-plugin');          $this->stencil->js('home-slider');          $this->stencil->css('home-slider');            $this->stencil->meta(array(              'author' => 'Nicholas Cerminara',              'description' => 'This is the home page of my website!',              'keywords' => 'stencil, example, fun stuff'          ));            $data['welcome_message'] = 'Welcome to my website using Stencil!';          $this->stencil->paint('home_view', $data);      }  }    /* End of file home.php */  /* Location: ./application/controllers/home.php */

模板:

<!doctype html>  <html>  <head>      <!-- robot speak -->          <meta charset="utf-8">      <title><?php echo $title; ?> | My Stencil Website</title>      <?php echo chrome_frame(); ?>      <?php echo view_port(); ?>      <?php echo apple_mobile('black-translucent'); ?>      <?php echo $meta; ?><!-- //loads data from $this->stencil->meta($args) in controller -->        <!-- icons and icons and icons and icons and icons -->      <?php echo favicons(); ?>        <!-- crayons and paint -->        <?php echo add_css(array('bootstrap', 'style')); ?>      <?php echo $css; ?><!-- //loads data from $this->stencil->css($args) in controller -->        <!-- magical wizardry -->      <?php echo jquery('1.9.1'); ?>      <?php echo shiv(); ?>      <?php echo add_js(array('bootstrap.min', 'scripts')); ?>      <?php echo $js; ?><!--  //loads page specific $this->stencil->js($args) from Controller (see docs) -->  </head>  <!-- $body_class will always be the class name -->  <body class="<?php echo $body_class; ?>">        <header>          <?php echo $header; ?>      </header>        <h1><?php echo $welcome_message; ?></h1>        <section class="content">          <?php echo $content; ?><!-- This loads home_view -->      </section>        <footer>          <?php echo $footer; ?>      </footer>    </body>  </html>

项目主页:http://www.open-open.com/lib/view/home/1403572141811