CodeIgniter 模板引擎:Stencil

jopen 10年前發布 | 19K 次閱讀 Stencil 模板引擎

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.baiduhome.net/lib/view/home/1403572141811

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!