Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

通过简单、懒惰且快速的方式,在CI中构建你的Smarty作为应用程序的view。 An easy way to integrate Smarty 3.x.x in CodeIgniter 2.x.x.

Notifications You must be signed in to change notification settings

libingxin01/Codeigniter-Smarty

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

4 Commits

Repository files navigation

Introduction(簡介)

en: This library is a easy & lazy & fast to help you building Smarty views in Codeigniter.

You can use this library to substitute Codeigniter-Parser library, or direct use Smarty build-in function to write your web application.

zh: 這個類庫是一項可以讓你在 Codeigniter 之中, 簡單、懶惰、快速 的 Smarty 樣版引擎建置方法。

你可以直接使用這個類庫取代內建的 Codeigniter-Parser 類庫來使用它,或是直接使用傳統的 Smarty 內建函式使用它。

How to install? (如何安裝?)

  1. Go http://www.smarty.net/ and download Smarty library.

  2. Extract Smarty zip file into your third_party dir like a example: /application/third_party/Smarty-3.1.11/

    Example path /application/third_party/Smarty-3.1.11/demo /application/third_party/Smarty-3.1.11/libs /application/third_party/Smarty-3.1.11/change_log.txt /application/third_party/Smarty-3.1.11/COPYING.lib /application/third_party/Smarty-3.1.11/README

  3. Get this library into dir: /application/libraries/template.php

How to use? (如何使用?)

Basic syntax (基本語法)

in Controller

<?php
function index() {
	// You also can setting autoload in /application/config/autoload.php
	$this->load->library( 'template' );
	// Such as traditional syntax
	$this->template->assign( 'title', 'CI-Smarty Example' );
	$this->template->assign( 'keyword', 'codeigniter,smarty,template' );
	$this->template->display( 'home/index', $assign ); // default file ext is `.html`
}

in HTML

<!DOCTYPE HTML>
<html>
<head>
	<title>{$title} - website name</title>
	<meta name="keywords" content="{$keyword}">
</head>

How to return a fetched html string? (如何返回html字串供額外使用?)

in Controller

<?php
function index() {
	$this->load->library( 'template' );
	$data['title'] = 'CI-Smarty Example';
	$data['keyword'] = 'codeigniter,smarty,template';
	// Such as traditional syntax
	$string = $this->template->parse( 'home/index', $data, true ); // default file ext is `.html`
	echo $string;
}

How to access $CI in views? (如何在視圖中, 存取CI物件?)

in Controller

<?php
function index() {
	$this->load->library( 'template' );
	$CI =& get_instance();
	$this->template->assign( 'CI', $CI );
	$this->template->display( 'home/index', $assign ); // default file ext is `.html`
}

in HTML

<!DOCTYPE HTML>
<html>
<head></head>
<body>
	hello, world<br />
	This site's name is {$CI->config->item( 'site_name' )}.
</body>

Traditional function? (smarty的傳統函數?)

{nocache}{/nocache}

in HTML

<!DOCTYPE HTML>
<html>
<head></head>
<body>
	hello, world the time is {nocache}{$smarty.now|date_format}{/nocache}
</body>

About

通过简单、懒惰且快速的方式,在CI中构建你的Smarty作为应用程序的view。 An easy way to integrate Smarty 3.x.x in CodeIgniter 2.x.x.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

AltStyle によって変換されたページ (->オリジナル) /