Stencil 介绍
Stencil 是一个 CodeIgniter
的模板引擎,通过简单可靠的方式来渲染 HTML 页面。
控制器:
<?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>